Prev | Current Page 147 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

To combat this problem, you need to use the bitwise AND ( & )
operator, which will help you filter your values from the containing variable.
haXe supports three operators for bitwise filtering. They are AND ( & ), OR ( | ), and XOR ( ^ ). The AND
and OR filters work similarly to the comparison equivalents, except that, instead of comparing true or
false expressions and returning a resulting boolean value, they instead compare bits and return a
resulting bit value. XOR, which stands for eXclusive OR, compares two bits and returns 1 only if one of
the bits is a 1. If both bits are or neither bit is a 1, then XOR will return 0. This is quite different to OR,
which will return a 1 if either bit or both bits are 1. AND will return a 1 if neither bit is 0. Let ??™ s see some
examples; scan the bits in each pair and try to guess what result each filter will return:
Now that you know what the filters do, you can look at ways in which to retrieve your values. If you
have a 32 - bit integer and wish only to retrieve the first 8 bits, you can apply the AND filter using a value
that has all of the first 8 bits filled as 1 and all remaining bits filled with 0.


Pages:
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159