InterviewStack.io LogoInterviewStack.io

Bitwise Operations and Bit Manipulation Questions

Covers working with binary representations of integers and performing fundamental bitwise operations including and, or, xor, not, and left and right shifts. Includes techniques for testing setting clearing and toggling individual bits, creating and applying masks, and using bit fields and bit packed structures for compact storage. Addresses endianness and byte order considerations, bit level register manipulation for hardware and embedded systems, and efficient bit algorithms such as population count parity leading and trailing zero detection and sign extension. Encompasses practical uses in protocol parsing flag management performance optimizations and cryptographic primitives including substitution and diffusion concepts. Candidates may be assessed with coding problems that require bit tricks and algorithmic reasoning as well as design questions about data layout and low level interfaces.

HardSystem Design
57 practiced
Design a Bloom filter to fit in 8 KB of SRAM for up to 500 32-bit device IDs with a target false-positive rate under 1%. Choose bit-array size m and number of hash functions k, explain how to implement add() and contains() using bitwise operations efficiently, and discuss using double-hashing to reduce hash computations on an MCU.
EasyTechnical
59 practiced
When is it safe to replace multiplication or division by powers of two with left or right shifts in C? Give examples where this transformation is incorrect (signed negatives, overflow) and provide safe idiomatic patterns that embedded developers can use for speed-sensitive code.
MediumTechnical
50 practiced
You must store 10,000 boolean occupancy flags on a microcontroller with 64 KB of RAM. Design an efficient bit-packed storage and implement APIs set_flag(i), clear_flag(i), and test_flag(i) in C. Discuss time complexity, choice between uint8_t/uint32_t backing store, alignment and atomicity considerations on 8-bit vs 32-bit buses.
MediumTechnical
59 practiced
Implement int32_t sign_extend32(uint32_t value, unsigned bit_width) in C. The function takes an unsigned value that represents a signed integer with bit_width bits (1..32) and returns the correctly sign-extended 32-bit signed value. Avoid undefined behavior and make the implementation efficient on embedded targets.
MediumTechnical
62 practiced
Implement rotate-left and rotate-right functions for 32-bit unsigned integers in C: uint32_t rol32(uint32_t x, unsigned n) and uint32_t ror32(uint32_t x, unsigned n). Do not use compiler intrinsics; handle arbitrary n (including n >= 32) safely and efficiently.

Unlock Full Question Bank

Get access to hundreds of Bitwise Operations and Bit Manipulation interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.