0

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!

  • 2
    0x88, when written in binary, is 0b10001000. Therefore, `index & 0x88` is zero precisely when both the 8th and 4th bits of index are 0. Usually this type of condition is used when you are testing for bit-based flags (in this case, the combination of flags indicated by the 8th and 4th flags being unset.) – dlev Apr 24 '13 at 05:36
  • 4
    See http://stackoverflow.com/questions/1746613/bitwise-operation-and-usage/1746642#1746642 – paxdiablo Apr 24 '13 at 05:39

3 Answers3

3

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.

Yuushi
  • 25,132
  • 7
  • 63
  • 81
2

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)

RoneRackal
  • 1,243
  • 2
  • 10
  • 16
0

& is the bitwise and operator (when applied to numbers).

For example, 110 & 101 = 100

0x88 is 10001000 in binary.

Ofiris
  • 6,047
  • 6
  • 35
  • 58