Can anyone show me how this operation works? Index is number and it can be any number from 0 to 128. I just don't understand how (index & 0x88) can be 0 or not.
Any help will be greatly appreciated!
Can anyone show me how this operation works? Index is number and it can be any number from 0 to 128. I just don't understand how (index & 0x88) can be 0 or not.
Any help will be greatly appreciated!
0x88
is equivalent to 10001000
in binary. Thus, it will be 0
iff the binary value of the index is 0xxx0xxx
, where x
is any binary digit.
The & operator is a bitwise AND, if the binary digits of 0x88 and corresponding spot in index are both 1, it will not == 0. In the opposite case, if none of the digits are both 1, then the outcome of the & will be 0
In this case, your hex number 88 is 10001000 in binary, so (index & 10001000) can equal to 0 as long as index has 0 in it's 4th and 8th positions (for example, 01110111)
&
is the bitwise and
operator (when applied to numbers).
For example, 110 & 101 = 100
0x88
is 10001000
in binary.