Hi Tony,
Yes, the & operator is bitwise AND.
As input it takes two numbers, it then compares them bit by bit. Think of it like having running each bit in both numbers to a two-input AND-gate, (8 gates, one for each bit) the output of each gate is wired into the result variable. Just as with a real AND-gate both inputs (the same bit in the two numbers) have to set in order for the output (the bit in the result) to be set.
Result = %10101010 & %11111111
Here Result be a copy of the first number because all bits in the second number is set. Any bit which is SET in both numbers will be set in the result.
Result = %10101010 & %0000000
Here Result will be all zeros because the second number is all zeros.
Result = %10101010 & %11110000
Here Result will be %10100000 be because only the four bits of the second number are set.
Result = %10101010 & %00111100
Here Result will be 00101000 because, well I suppose you get it by now ;-)
/Henrik.
Bookmarks