188-Binary in Axcess
Frequently Asked Questions
Table of Contents
Brand:
- AMX
Models:
- Axcess
Question:
How do I implement binary in Axcess?
Answer:
Shift to the right ( >> operator in C++ ) :
Example : x >> 2 (shift x 2 positions to the right)
x = x / 4
i.e., x = $32 (binary 00110010)
When you shift the bits 2 positions to the right, you get
00001100.
OR
b8b7b6b5b4b3b2b1 --> 00b8b7b6b5b4b3 b2b1 have been removed.
x = x / 4
x = ($32 / 4)
x = $0C ---> 00001100
(shift right 1 place = divide by 2, 2 places = divide by 4, 3 places = divide by 8 )
Shift to the left ( << operator in C++ ) :
Example : x << 3 (shift x 3 positions to the left)
x = x * 8
i.e., x = $32 (binary 00110010)
When you shift the bits 3 positions to the left, you get 00110010000. OR
b8b7b6b5b4b3b2b1 --> b8b7b6 b5b4b3b2b1000
x = x * 8 x = ($32 * 8)
x = $190 ---> 000110010000
( shift left 1 place = multiply by 2, 2 places = multiply by 4, 3 places = multiply by 8 )
Get 1's compliment:
x = BNOT x
OR x = $FF - x
Get 2's compliment:
x = (BNOT x) + 1
OR x = ($FF - x) + 1
Another way to get the 2's compliment:
x = 0 - x
This will give the same answer as x = (BNOT x) + 1 and compiles with 1 less byte of Ax memory (whoopie!)
Cool trick:
Adding the 2's compliment of a number will subtract the number from the value.
y - x = y + (0 - x)
Interpret 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 --> $01
Binary OR (BOR "|" )
x = $19 ---> 00011001
x = x BAND $03 ---> 00011001 BOR
00000011
00011011 --> $1B
Binary Exclusive OR -- (BXOR "^")
x = $19 ---> 00011001
x = x BAND $03 ---> 00011001 BXOR
00000011
00011010 --> $1A