Decode and encode the data#

Problem Description#

In this example the decoding of the CDB data (KFIX value from @20/0 Nodes) is examined. E.g. KFIX value for node 1 (KFIX=112) and for node 11 (KFIX=113). What does it mean?

In CDBASE.CHM you can find the description on how to encode/decode the KFIX value (degree of freedoms for nodes). A value 112 doesn’t mean nothing to us when we do not know what it means.

Example: CDBASE.CHM description#
@2# KFIX [int] degree of freedoms old definition:

#0     all fixed
&1     displacement uX
&2     displacement uY
&4     displacement uZ
&8     rotation PHIX
&16    rotation PHIY
&32    rotation PHIZ
&64    twisting dPHIx/dx
&128   split continuous beams flag
&256   ux-uy-uz may be suppressed
&512   phix-phiz may be suppressed
&1024  warping may be suppressed

For KFIX=112

112 - 1024 = -912 < 0

warping my be suppressed

FALSE

112-512 = -400 < 0

phix-phiz may be suppressed

FALSE

112-256 = -144 < 0

ux-uy-uz may be suppressed

FALSE

112-128 = -16 < 0

split continuous beams flag

FALSE

112-64 = 48 > 0

twisting dPHIx/dx

TRUE

48-32 = 16 > 0

rotation PHIZ

TRUE

16-16 = 0 = 0

rotation PHIY

TRUE


twisting dPHIx/dx

= PX + PY + PZ + MX + MY + MZ

rotation PHIZ

= -MZ

rotation PHIY

= -MY

Result

= PX + PY + PZ + MX = PPMX

For KFIX=113

113 - 1024 = -912 < 0

warping my be suppressed

FALSE

113-512 = -399 < 0

phix-phiz may be suppressed

FALSE

113-256 = -143 < 0

ux-uy-uz may be suppressed

FALSE

113-128 = -15 < 0

split continuous beams flag

FALSE

113-64 = 49 > 0

twisting dPHIx/dx

TRUE

49-32 = 17

rotation PHIZ

TRUE

17-16 = 1 > 0

rotation PHIY

TRUE

1-8 = -7 < 0

rotation PHIX

FALSE

1-4 = -7 < 0

displacement uZ

FALSE

1-2 = -7 < 0

displacement uY

FALSE

1-1 = 0 = 0

displacement uX

TRUE


twisting dPHIx/dx

= PX + PY + PZ + MX + MY + MZ

rotation PHIZ

= -MZ

rotation PHIY

= -MY

displacement uX

= -PX

Result

= PY + PZ + MX = XPMX

Problem Solution#

Below you will find a trivial code solution for the problem above. We will use the bitwise operator.

Example: Encoding/Decoding KFIX#
Function ConvertDisplacements(result As Long) As String
   Dim x As Single
   Dim value As String
   value = "PXPYPZMXMYMZ"

   ' Check for bit 64
   x = (64 And result)
   value = "PXPYPZMXMYMZ"

   ' Check for bit 32 = MZ
   x = (32 And result)
      If x > 0 Then
      value = Replace(value, "MZ", vbNullString , , , vbTextCompare)
   End If

   ' Check for bit 16 = MY
   x = (16 And result)
      If x > 0 Then
      value = Replace(value, "MY", vbNullString , , , vbTextCompare)
   End If

   ' Check for bit 8 = MX
   x = (8 And result)
      If x > 0 Then
      value = Replace(value, "MX", vbNullString , , , vbTextCompare)
   End If

   ' Check for bit 4 = PZ
   x = (4 And result)
      If x > 0 Then
      value = Replace(value, "PZ", vbNullString , , , vbTextCompare)
   End If

   ' Check for bit 2 = PY
   x = (2 And result)
      If x > 0 Then
      value = Replace(value, "PY", vbNullString , , , vbTextCompare)
   End If

   ' Check for bit 1 = PX
   x = (1 And result)
      If x > 0 Then
      value = Replace(value, "PX", vbNullString , , , vbTextCompare)
   End If

   ' Replace the text to input
   value = Replace(value, "PXPYPZ", "PP", , , vbTextCompare)
   value = Replace(value, "MXMYMZ", "MM", , , vbTextCompare)
   value = Replace(value, "PYPZ", "XP", , , vbTextCompare)
   value = Replace(value, "PXPZ", "YP", , , vbTextCompare)
   value = Replace(value, "PXPY", "ZP", , , vbTextCompare)
   value = Replace(value, "MYMZ", "XM", , , vbTextCompare)
   value = Replace(value, "MXMZ", "YM", , , vbTextCompare)
   value = Replace(value, "MXMY", "ZM", , , vbTextCompare)
   value = Replace(value, "PPMM", "F", , , vbTextCompare)

   ConvertDisplacements = value
End Function