This video explains bitwise operators such as bitwise AND, OR, XOR, NOT, left shift, and right shift (for unsigned).
NOTE: In the video I have explained shift operators for unsigned integers, but for right shift on signed integers, the sign bit is copied.
For example, in 4-bit representation:
1100 right shift 1 gives 1110
if 1100 was a signed 4-bit integer.
The left shift operator behaves the same for signed and unsigned integers.
⚠️ BUT: left-shifting a signed number can be undefined if:
it overflows
it changes the sign bit
Example:
01000000 left shift 1
might overflow(if left bit is considered sign bit) and become negative — undefined behavior in C/C.
Unsigned left shift is always safe.
general precedence of bitwise operators precedence. high to low.
Bitwise NOT ~: Has high precedence.
Bitwise Shift Operators: left and right shift
Bitwise AND &
Bitwise XOR ^
Bitwise OR |