The bitewise operators in Java are listed in following table:
Operator | Name | Example | Result | Description |
a & b | AND | 3 & 5 | 1 | 1 if both bits are 1. |
a | b | OR | 3 | 5 | 7 | 1 if either bit is 1. |
a ^ b | XOR (Ex-OR) | 3 ^ 5 | 6 | 1 if both bits are different. |
~a | NOT | ~3 | -4 | Inverts bit. |
n << p | Left Shift | 3 << 2 | 12 | Shift the bits of n left p positions. Zero bits are shifted into low-order positions. |
n >> p | Right Shift | 5 >> 2 | 1 | Shift the bits of n right p positions. If n is a 2’s complement signed number, the sign bit is shifted into the high-order positions. |
n >>> p | Right Shift | -4 >>> 28 | 15 | Shift the bits of n right p positions. Zeros bits are shifted into high-order positions. |
Ask Question