Recall & Review
beginner
What does it mean to check if a bit is set in a number?
It means to find out if a specific bit position in a number is 1 (on) or 0 (off).
Click to reveal answer
beginner
Which operator is commonly used in C to check if a bit is set?
The bitwise AND operator (&) is used to check if a bit is set.
Click to reveal answer
intermediate
How do you check if the 3rd bit (counting from 0) is set in a variable 'x'?
Use the expression: (x & (1 << 3)) != 0. This shifts 1 to the 3rd bit and ANDs with x.
Click to reveal answer
beginner
Why do we use (1 << n) when checking bits?
Because (1 << n) creates a number with only the nth bit set to 1, which helps isolate that bit.
Click to reveal answer
beginner
What will the expression (x & (1 << n)) return if the nth bit is not set?
It will return 0, meaning the bit is off.
Click to reveal answer
What does the expression (x & (1 << 2)) check?
✗ Incorrect
The expression shifts 1 by 2 bits, so it checks the 2nd bit (counting from 0).
What operator is used to isolate a bit in embedded C?
✗ Incorrect
The bitwise AND operator (&) isolates bits by comparing bits of two numbers.
If (x & (1 << n)) equals zero, what does it mean?
✗ Incorrect
If the result is zero, the nth bit in x is not set (off).
What does (1 << 5) do in C?
✗ Incorrect
It shifts the number 1 left by 5 bits, creating a number with only bit 5 set.
Which of these is a correct way to check if bit 0 is set in variable x?
✗ Incorrect
x & 1 checks if the least significant bit (bit 0) is set.
Explain how to check if a specific bit is set in a number using embedded C.
Think about isolating one bit using a mask.
You got /4 concepts.
Describe why shifting 1 by n positions helps in checking bits.
Imagine turning on only one light in a row of lights.
You got /3 concepts.