I'm working on a driver, and I'm having trouble finding a way to manipulate the bits I want to on a digital register.
The register has 20 bits (0-19) and I'm only concerned with writing over the last two (19,18). These bits are part of a hex representing that section, so to visualize, the #'s are what I want to change:
Hex 5 B 0 F
[##00 0101 1011 0000 1111]
All of the other bits must be kept as they are—the example above is arbitrary, so the masking has to handle any combination of bits.
I've tried creating a mask with any combination of &
and |
with 0xFFFFF
and also 0x00000
but neither change just the first two bits of the hex that will be written.
Any ideas to get this to function would be great; and if you could explain how the solution works, even better.