October 15, 1999 - The Bitwise OR Operator
October 15, 1999 The Bitwise OR Operator Tips: October 1999
Yehuda Shiran, Ph.D.
|
Bit1 Bit2 Bit1 | Bit2 0 0 0 0 1 1 1 0 1 1 1 1
The OR operator, like all other bitwise operators, can take only numeric values as its operands. Since JavaScript does not support bit-length variables, you have to do your bitwise math with byte-length operands, i.e. with integers that are less than 256. Any operand longer than a byte (greater than 255) will be chopped and only the LSB (Least Significant Byte) will be used.
Let's do a simple calculation:
Name Decimal Hex Binary Op1 70 0x46 0 1 0 0 0 1 1 0 Op2 121 0x79 0 1 1 1 1 0 0 1 Op1 | Op2 127 0x7F 0 1 1 1 1 1 1 1