Recall & Review
beginner
What does the least significant bit (LSB) of a binary number tell us about the number?
The least significant bit (LSB) tells us if the number is even or odd. If LSB is 0, the number is even; if LSB is 1, the number is odd.
Click to reveal answer
beginner
How can you check if a number is even using bitwise AND in C?
Use the expression (number & 1). If the result is 0, the number is even; if it is 1, the number is odd.
Click to reveal answer
intermediate
Why is using bitwise operations to check even or odd numbers efficient?
Bitwise operations work directly on binary digits and are faster than division or modulus operations, making them efficient for checking even or odd.
Click to reveal answer
beginner
What is the output of this C code snippet? <br>
int n = 6; if (n & 1) printf("Odd"); else printf("Even");The output is "Even" because 6 in binary ends with 0, so (6 & 1) is 0.
Click to reveal answer
intermediate
Explain the difference between using modulus (%) and bitwise AND (&) to check even or odd.
Modulus (%) divides the number and checks the remainder, which is slower. Bitwise AND (&) checks the last bit directly, which is faster and uses less CPU.
Click to reveal answer
Which bitwise operation is used to check if a number is even or odd?
✗ Incorrect
AND (&) with 1 isolates the least significant bit to check if the number is even or odd.
What does the expression (number & 1) return if the number is odd?
✗ Incorrect
For odd numbers, the least significant bit is 1, so (number & 1) returns 1.
Why might bitwise checking be preferred over modulus for even/odd checks in embedded systems?
✗ Incorrect
Bitwise operations are faster and use less CPU, which is important in resource-limited embedded systems.
What is the output of this code? <br>
int x = 7; if (x & 1) printf("Odd"); else printf("Even");✗ Incorrect
7 is odd, so (7 & 1) is 1, printing "Odd".
If (number & 1) == 0, what can we say about the number?
✗ Incorrect
If the least significant bit is 0, the number is even.
Describe how to check if a number is even or odd using bitwise operations in C.
Think about the last bit in binary.
You got /4 concepts.
Explain why bitwise operations are efficient for checking even or odd numbers compared to modulus.
Consider how computers handle bits versus division.
You got /4 concepts.
