Lets say I have a number like 0x448
. In binary this is 0100 0100 1000
.
How do I set the bits 1, 2 and 3 to either all 0's or all 1's using bit-wise operations? When I say the first three, I'm counting the rightmost bit as the zero bit.
So, for example
Bits as 1's:
b12 b0
0100 0100 1110
^^^
Bits as 0's:
b12 b0
0100 0100 0000
^^^
I'm guessing that to set them to 1's I use bit-wise OR with a mask of 14 (0x000e)? But if that is the case, how do I do something similar for clearing the bits?
Related:
- How do you set, clear and toggle a single bit in C? (syntax varies, but the operations are the same)