Appendix A. CRBasic Programming Instructions
<=
Less than or equal
to
A.7.3 Bitwise Operations
Bitwise shift operators (
<<
and
>>
) allow CRBasic to manipulate the position of
bits within a variable declared
As Long
(integer). Following are example
expressions and expected results:
•
&B00000001 << 1
produces
&B00000010
(decimal
2
)
•
&B00000010 << 1
produces
&B00000100
(decimal
4
)
•
&B11000011 << 1
produces
&B10000110
(decimal
134
)
•
&B00000011 << 2
produces
&B00001100
(decimal
12
)
•
&B00001100 >> 2
produces
&B00000011
(decimal
3
)
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 zeros.
Smart sensors, or a communication protocol, may output data that are compressed
into integers that are composites of "packed" fields. This type of data
compression is a tactic to conserve memory and communication bandwidth.
Following is an example of data compressed into an eight-byte integer:
A packed integer that is stored in variable
input_val
will be unpacked into
three integers individually stored in
value_1
,
value_2
, and
value_3
. In the
packed integer, the information that is unpacked into
value_1
is stored in bits
7 and 6,
value_2
is unpacked from bits 5 and 4, and
value_3
from bits 3, 2, 1,
and 0. The CRBasic code to do this unpacking routine is shown in CRBasic
example
Using Bit-Shift Operators
(p. 564).
With unsigned integers, shifting left is equivalent to multiplying by two. Shifting
right is equivalent to dividing by two.
The operators follow:
<<
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.
564
Summary of Contents for CR1000
Page 2: ......
Page 4: ......
Page 6: ......
Page 32: ......
Page 36: ......
Page 38: ......
Page 40: ......
Page 60: ...Section 4 System Quickstart Figure 16 PC200W View Line Graph 60 ...
Page 96: ......
Page 98: ...98 ...
Page 302: ......
Page 453: ...Section 8 Operation Figure 115 Using the Keyboard Display 453 ...
Page 456: ...Section 8 Operation Figure 118 Real Time Custom 456 ...
Page 457: ...Section 8 Operation 8 8 1 3 Final Memory Tables Figure 119 Final Memory Tables 457 ...
Page 458: ...Section 8 Operation 8 8 2 Run Stop Program Figure 120 Run Stop Program 458 ...
Page 460: ...Section 8 Operation Figure 122 File Edit 460 ...
Page 461: ...Section 8 Operation 8 8 4 PCCard Memory Card Display Figure 123 PCCard CF Card Display 461 ...
Page 478: ......
Page 506: ......
Page 536: ......
Page 636: ......
Page 642: ......
Page 644: ......
Page 676: ......
Page 677: ......