A.6.4 compound-assignment operators, Table 117. compound-assignment operators – Campbell Scientific CR1000 Measurement and Control System User Manual
Page 494

Appendix A. CRBasic Programming Instructions
494
The result of these operators is the value of the left hand operand with all of its
bits moved by the specified number of positions. The resulting "holes" are filled
with zeroes.
Consider a sensor or protocol that produces an integer value that is a composite of
various "packed" fields. This approach is quite common to conserve bandwidth
and/or storage space. Consider the following example of an eight-byte value:
• bits 7-6: value_1
• bits 5-4: value_2
• bits 3-0: value_3
Code to extract these values is shown in CRBasic example Using Bit-Shift
Operators
(p. 494).
With unsigned integers, shifting left is equivalent to multiplying by two. Shifting
right is equivalent to dividing by two.
<<
Bitwise left shift
Syntax
Variable = Numeric Expression >> Amount
>>
Bitwise right shift
Syntax
Variable = Numeric Expression >> Amount
&
Bitwise AND assignment ‐‐ Performs a bitwise AND of a variable with an
expression and assigns the result back to the variable.
A.6.4 Compound-assignment operators
Table 117. Compound-Assignment Operators
Symbo
l
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 String variable and assigns the result to the
variable.
-=
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.