Bit Manipulation Quiz
Editorial
16 questions across the three Bit Manipulation lessons and the section's problems: bits, the operators and negative numbers in each language; setting, clearing and counting bits; XOR's cancelling, swaps and adding without +; and bitmasks as sets, the AND of a range and division by doubling. Pick an answer to see whether it's right and why. Nothing is saved, so you can take it again.
If one trips you up, its lesson is Introduction to Bit Manipulation, XOR Tricks or Bitmasks and Bitwise Arithmetic.
Quiz
1 / 16Multiple choice
What do 13 & 6, 13 | 6 and 13 ^ 6 give?
Multiple choice
In Python, what does
-12 & 0xFFFFFFFF give?Multiple choice
In Java,
int s = 33; then 1 << s. What do you get?Multiple choice
x is 101001. Set bit 1, clear bit 2, then toggle bit 5, counting bits from 0 at the right. What is x now?
Multiple choice
Which test is true for exactly the powers of two?
Multiple choice
Toggle Rightmost Unset Bit on 11: what comes out?
Multiple choice
Counting set bits with
while x: x &= x - 1. On 200, how many rounds does the loop run?Multiple choice
Minimum Bit Flips to Convert Number from 29 to 14: how many flips?
Multiple choice
Reversing the 8 bits of 6, 00000110, gives which number?
Multiple choice
a = 12 and b = 7. After
a ^= b; b ^= a;, the first two lines of the XOR swap, what do a and b hold?Multiple choice
What is the XOR of every value in [3, 5, 3, 6, 6, 5, 5, 9]?
Multiple choice
In Python, Sum of Two Integers' loop runs without the 32-bit mask. Which sum never finishes?
Multiple choice
Masks A = 10110 and B = 01100 are sets. Which mask holds what is in A but not in B?
Multiple choice
Subsets of [p, q, r, s] by counting masks 0 to 15, with p on bit 0 and s on bit 3. How many of them hold both p and s?
Multiple choice
Bitwise AND of Numbers Range on [37, 44]?
Multiple choice
Division by doubling on 90 / 7: how many subtractions does it make?