Bitwise AND: &
- Last UpdatedNov 07, 2016
- 1 minute read
Compares the binary representations of two integer numbers, bit for bit, and returns a result according to the following table:
|
Bit in first operand |
Bit in second operand |
Bit in result |
|---|---|---|
|
0 |
0 |
0 |
|
0 |
1 |
0 |
|
1 |
0 |
0 |
|
1 |
1 |
1 |
You can use this operator to quickly "mask out" (set to 0) certain parts of a bit pattern. For example, the following statement masks out the upper 24 bits of the IntTag tag:
IntTag = IntTag & 255;
As shown in the table, the result bit is always 0 if one of the operand bits is 0. In the binary representation of 255, only the lower 8 bits are 1, so the 24 remaining 0-bits cause all the corresponding bits in the result to be set to 0.
Valid operands
Any Integer value.
Data type of return value
Integer