Question.2
A developer wants to update the MODE field (bits 12–15) in a 16-bit register from 0xA to 0x5. The register currently holds 0xA3F5. He writes:
0xA
0x5
0xA3F5
reg |= (0x05 << 12);
What is wrong with this code?
Select Answer
The shift amount should be 8, not 12
The old MODE bits are not cleared — the new value gets OR'd with the existing value- will set unintended value.
To set the right value, developer need to use “&=” operator.
&=
Nothing — OR correctly replaces the field