Bit Manipulation and Mathematical Reasoning Flashcards
6 cards from real CodeSignal Technical Assessment practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 Bit Manipulation and Mathematical Reasoning flashcards as text
What does the expression `n & (n-1)` evaluate to when n is a power of 2?
Answer: 0
A power of 2 has exactly one set bit; subtracting 1 flips all lower bits, so ANDing gives 0.
How do you check if the k-th bit (0-indexed) of integer n is set?
Answer: n & (1 << k)
Shifting 1 left by k positions creates a mask; ANDing with n isolates that bit, giving a non-zero result if it is set.
What is 5 XOR 3 in decimal?
Answer: 6
5 is 101 and 3 is 011 in binary; XOR gives 110, which equals 6 in decimal.
What does left-shifting an integer n by 1 position (`n << 1`) effectively compute?
Answer: n * 2
Left-shifting by 1 appends a zero bit on the right, which doubles the value in base-2 representation.
Which bit trick isolates the lowest set bit of integer n?
Answer: n & (-n)
The two's complement of n (-n) flips all bits and adds 1, so n & (-n) keeps only the rightmost set bit.
What is the result of `n ^ n` for any integer n?
Answer: 0
XORing any value with itself cancels every bit, producing 0.
Written and edited by Nathan Beja, founder of Practice Test Geeks, with AI assistance. Exam facts are checked against the official sources linked below. Editorial policy
Sources & references
Exam facts on this page (fees, format, dates, passing scores) are checked against these official sources; the date is our last check. Editorial policy
- support.codesignal.com — Time limit, eligibility, retake policy, score validity, exam format, passing score, score release · verified Nov 2026
- codesignal.com — Test delivery · verified Nov 2026