Propeller Manual

Table Of Contents
2: Spin Language Reference – Operators
Bitwise Shift Left ‘<<’, ‘<<=
The Bitwise Shift Left operator shifts the bits of the first operand left by the number of bits
indicated in the second operand. The original MSBs (leftmost bits) drop off and the new
LSBs (rightmost bits) are set to zero. Bitwise Shift Left can be used in both variable and
integer constant expressions, but not in floating-point constant expressions. Example:
X := Y << 2
If Y started out as:
%10000000 01110000 11111111 00110101
...the Bitwise Shift Left operator would shift that value left by two bits, setting
X to:
%00000001 11000011 11111100 11010100
Since the nature of binary is base-2, shifting a value left is like multiplying that value by
powers of two, 2
b
, where b is the number of bits shifted.
Bitwise Shift Left has an assignment form,
<<=, that uses the variable to its left as both the
first operand and the result destination. For example,
X <<= 4 'Short form of X := X << 4
Here, the value of X is shifted left four bits and is stored back in X. The assignment form of
Bitwise Shift Left may also be used within expressions for intermediate results; see
Intermediate Assignments, page 147.
Bitwise Shift Right ‘
>>’, ‘>>=
The Bitwise Shift Right operator shifts the bits of the first operand right by the number of bits
indicated in the second operand. The original LSBs (rightmost bits) drop off and the new
MSBs (leftmost bits) are set to zero. Bitwise Shift Right can be used in both variable and
integer constant expressions, but not in floating-point constant expressions. Example:
X := Y >> 3
If Y started out as:
%10000000 01110000 11111111 00110101
...the Bitwise Shift Right operator would shift that value right by three bits, setting
X to:
%00010000 00001110 00011111 11100110
Propeller Manual v1.1 · Page 161