195-How To shift bits
Technical Support Guide
Table of Contents
Brand:
- AMX
Models:
- Netlinx
Overview:
Shift to the right ( >> operator in C++ ) :
Example : x >> 2 (shift x 2 positions to the right)
x = x / 4i.e., x = $32 ---> 00110010 When you shift the bits 2 positions to the right, this is what you get 00001100.
OR
b8b7b6b5b4b3b2b1 --> 00b8b7b6b5b4b3 b2b1 have been removed.
x = x / 4
x = ($32 / 4)
x = $0C ---> 00001100Shift to the left ( << operator in C++):
Example : x << 3 (shift x 2 positions to the left)
x = x * 8i.e., x = $32 ---> 00110010 When you shift the bits 3 positions to the left, this is what you get 00110010000.
OR
b8b7b6b5b4b3b2b1 --> b8b7b6 b5b4b3b2b1000
x = x * 8
x = ($32 * 8)
x = $190 ---> 000110010000 Get 1's compliment
x = BNOT x
OR x = $FF - xGet 2's compliment x = (BNOT x) + 1
OR x = ($FF - x) + 1Interpret this C++ statement : b=a? x:y
if (a)
{
b = x
}
else
{
b = y
}Binary AND (BAND "&" )
x = $19 ---> 00011001
x = x BAND $03 ---> 00011001 BAND
00000011
------------------------------
00000001 --> $01Binary OR (BOR "|" )
x = $19 ---> 00011001
x = x BAND $03 ---> 00011001 BOR
00000011
------------------------------
00011011 --> $1BBinary XOR (BXOR "^")
x = $19 ---> 00011001
x = x BAND $03 ---> 00011001 BXOR
00000011
------------------------------
00011010 --> $1A