28. Bit Field Operations-i

Question.4

A UART control register has the following 8-bit layout:

76543210
PARITYBAUDEN

The register currently holds 0x1F. A developer needs to change the BAUD field to 3 without affecting other bits. 

Code A:

reg &= ~(0x07 << 1);
reg |= (3 << 1);

Code B:

reg &= ~(0x07 << 1);
reg |= (3 << 2);

Code C:

reg = (reg & 0xF1) | (3 << 1);

Code D:

reg |= (3 << 1);

Which code(s) is/are correct?

Note: Multiple options may be correct.

Need Help? Refer to the Quick Guide below

Select Multiple Options

Restart quiz!