Definition:
Bitwise operators work on binary numbers (0 and 1).
It performs operations on each bit of a number and returns the result in binary form (0 or 1).
They are used for AND, OR, NOT, XOR, and shifting bits operations.
There are different types of bitwise operators as follows:
- AND Operator (&)
- OR Operator (|)
- NOT Operator (~)
- XOR Operator (^)
- Left Shift Operator (<<)
- Right Shift Operator (>>)
Bitwise Operator Table:
| Operator | Symbol | What it does |
|---|---|---|
| AND | & | Both bits must be 1 → 1 |
| OR | | | At least one 1 → 1 |
| XOR | ^ | Different bits → 1 |
| NOT | ~ | Flips bits (0 ↔ 1) |
| Left Shift | << | Multiplies number by 2 |
| Right Shift | >> | Divides number by 2 |
