Recall & Review
beginner
What does it mean to set a specific bit in a register?
Setting a specific bit means changing that bit's value to 1 while leaving other bits unchanged.
Click to reveal answer
beginner
Which operator is commonly used in C to set a specific bit in a register?
The bitwise OR operator (|) is used to set a specific bit.
Click to reveal answer
intermediate
Explain the expression: register |= (1 << n);
It shifts 1 to the left by n positions to create a mask with only bit n set, then ORs it with the register to set bit n.
Click to reveal answer
intermediate
Why is it important to use bitwise OR instead of assignment when setting a bit?
Using OR preserves other bits in the register; assignment would overwrite all bits, losing existing data.
Click to reveal answer
beginner
Write a C code snippet to set bit 3 of a register named REG.
REG |= (1 << 3);
Click to reveal answer
What does the expression (1 << 5) do in C?
✗ Incorrect
The << operator shifts the number 1 left by 5 bits, creating a mask with bit 5 set.
Which operator is used to set a bit without changing other bits?
✗ Incorrect
The OR operator sets bits to 1 where the mask has 1s, preserving other bits.
What happens if you use assignment (=) instead of OR (|=) to set a bit?
✗ Incorrect
Assignment replaces the whole register value, so other bits are lost.
How do you set bit 0 of a register named REG?
✗ Incorrect
Shifting 1 by 0 leaves it as 1, so OR sets bit 0.
What is the result of REG |= (1 << n); if bit n was already set?
✗ Incorrect
OR with 1 keeps the bit set; no change if already set.
Describe how to set a specific bit in a register using C code.
Think about creating a mask with 1 shifted to the bit position.
You got /3 concepts.
Explain why using |= is better than = when setting a bit in a register.
Consider what happens to bits not targeted.
You got /3 concepts.