Recall & Review
beginner
What is bit manipulation in programming?
Bit manipulation means directly working with the individual bits of data, like turning bits on or off, shifting them left or right, or combining them using AND, OR, XOR operations.
Click to reveal answer
beginner
Why can bit manipulation be faster than arithmetic operations?
Bit manipulation uses simple CPU instructions that work directly on bits, which are usually faster and use less memory than arithmetic operations like multiplication or division.
Click to reveal answer
intermediate
Give an example when bit manipulation beats arithmetic.
Multiplying or dividing by powers of two can be done faster by shifting bits left or right instead of using * or / operators.
Click to reveal answer
beginner
What is a common bit manipulation trick to check if a number is even or odd?
Check the least significant bit using AND with 1. If (number & 1) is 0, the number is even; if 1, it is odd.
Click to reveal answer
intermediate
When should you avoid bit manipulation despite its speed?
Avoid bit manipulation when code readability and maintainability are more important, or when the performance gain is negligible compared to arithmetic clarity.
Click to reveal answer
Which bit operation can replace multiplication by 8?
✗ Incorrect
Shifting bits left by 3 positions multiplies the number by 2^3 = 8.
What does the expression (x & 1) == 0 check?
✗ Incorrect
The least significant bit is 0 for even numbers, so (x & 1) == 0 means x is even.
Why is bit manipulation often faster than arithmetic?
✗ Incorrect
Bit manipulation uses simple CPU instructions that operate directly on bits, making it faster.
Which operation is NOT a bit manipulation operation?
✗ Incorrect
Addition is an arithmetic operation, not a bit manipulation operation.
When is it better to avoid bit manipulation?
✗ Incorrect
Bit manipulation can make code harder to read, so avoid it when clarity and maintainability matter more.
Explain why bit manipulation can be faster than arithmetic operations and give an example.
Think about how CPUs handle bits versus numbers.
You got /3 concepts.
Describe a situation where using bit manipulation is not recommended despite its speed advantage.
Consider the trade-off between speed and understanding.
You got /4 concepts.
