Appendix A. CRBasic Programming Instructions
CRBasic Example 70. Using Bit-Shift Operators
'This program example demonstrates the unpacking of a packed integer. The binary value in
'variable input_val is unpacked resulting in three integers individually stored in variables
'value(1), value(2), and value(3). The information that is unpacked into value(1) is stored
'in 'bits 7 to 6 of input_val, value(2) is unpacked from bits 5 to 4, and value(3) from bits
'3 to 0, zero being the LSB or least-significant bit.
Public input_val As Long = &B01100011
Public value(3) As Long
BeginProg
'Unpack the input_val variable by masking all but the bit group of interest by using the
'AND function then shift the bit group to the right until the right-most bit is in the
'LSB position. The result is the unpacked value in decimal.
value(1) = (input_val AND &B11000000) >> 6
value(2) = (input_val AND &B00110000) >> 4
value(3) = (input_val AND &B00001111) 'Shifting not needed since right-most bit is already
'in the LSB position.
EndProg
A.7.4 Compound-Assignment Operators
Table 137. Compound-Assignment Operators
Symbol Name Function
^=
Exponent
assignment
Raises the value of a variable to the power of an
expression and assigns the result back to the variable.
*=
Multiplication
assignment
Multiplies the value of a variable by the value of an
expression and assigns the result to the variable.
+=
Addition
assignment
Adds the value of an expression to the value of a
variable and assigns the result to the variable. Also
concatenates a string expression to a variable
declared as STRING data type. Assigns the result to
the variable. See CRBasic example Concatenation
of Numbers and Strings
(p. 284).
-=
Subtraction
assignment
Subtracts the value of an expression from the value
of a variable and assigns the result to the variable.
/=
Division
assignment
Divides the value of a variable by the value of an
expression and assigns the result to the variable.
\=
Division integer
assignment
Divides the value of a variable by the value of an
expression and assigns the integer result to the
variable.
A.7.5 Logical Operators
AND
Performs a logical conjunction on two expressions.
Syntax
result = expr1 AND expr2
565