Member-only story

The Bit Manipulation Tricks You Need To Know For Coding Interview

From Bit To Bit With An Intuitive And Powerful Simple Idea

He Zhang
6 min readJan 19, 2024

The art of bit manipulation is an indispensable skill in the realm of programming, particularly for individuals preparing for technical interviews. The adeptness to directly manipulate bits not only unveils a profound comprehension of how computers process data but also empowers the seamless handling of specific computational tasks; as we all know, computers talk in bits.

Source: DALL·E, created by the Author. The computer uses bits underlying its display.

· Basic Operations
· Signed and Unsigned Shifting
· Iterating the Bits
· Subtraction by One
Remove the Last Set Bit
Get the Last Set Bit
· Adding By One
· Applications
· Other Tips for Interview
Tip 1
Tip 2

Basic Operations

The basic four bitwise operations include AND (&), OR (|), XOR (^), and NOT (~). Since they are fundamental, I assume we all know them well.

Signed and Unsigned Shifting

--

--

He Zhang
He Zhang

No responses yet