29. Bit Field Operations-ii

Question.3

A 32-bit configuration register contains a 5-bit counter field at bits 10–14. A developer extracts this field, increments it if below maximum, and writes it back. The register holds 0x00003C00.

uint32_t mask = 0x1F << 10;
uint32_t field = (reg & mask) >> 10;
if (field < 31) field += 1;
reg &= ~mask;
reg |= (field << 10);

What is the final value of reg?

Need Help? Refer to the Quick Guide below

Select Answer