Bnand()
Description
FUNCTION: bnand(number1, number2)
Both arguments are an integer that is treated as a bitfield. It performs a bitwise logical AND between number1 and the complement of number2 which has the effect of forcing certain bits in number1 off in the result.
- > think bnand(922,785)
- 138
In the above example, 922 in base 10 is equivalent to 39A in base 16 or 0011 1001 1010 in base 2. Likewise, 785 in base 10 is the same as 311 in base 16 and or 0011 0001 0001 in base 2. The complement of 785 (specifically the one's complement) is 1100 1110 1110 in base 2, and is a simple bitwise reversal of 1's and 0's.
- 0011 1001 1010 (922)
- (BAND)
- 1100 1110 1110 (Complement of 785)
- --------------
- 0000 1000 1010 (138)
The result may be expressed as 08A in base 16 or 138 in base 10.
Related Topics: shl(), shr(), band(), bor(), bxor().
(Realized after the fact that I could just change to a monospace font and make the example display a lot more clearly, though it still probably needs a bit of work. --Soylent 00:48, 3 December 2005 (EST))