Java Interviews: DSA - Bit Manipulation
Binary Left Shift (Multiplies):
a << b = a * (2^b)
Original : 0 0 0 0 1 0 1 : Int (5)
Shift Left: 0 1 0 1 0 0 : Int (20)
if a = 5, b = 2, hence 5 << 2 and 5 * (2 ^ 2) Therefore 20.
Binary Right Shift (Divides):
a << b = a / (2^b)
Original : 0 1 0 1 0...
shahsmit.hashnode.dev1 min read