Example
byte b = 127;
(initialize be to equal 11111111)
Now I only care about bits 1 and 0
how do i bit shift do get 00000011
I think this is called “masking bits” if I’m right?
I tried
b << 5
then
b>> 5
to zero out the other bits but that’s just wrong
My goal
switch ((myByte >> 3) & 3)
{
case 3:
resevered = true;
break;
case 2:
open = true;
break;
case 1:
SingleOnly = true;
break;
case 0:
daulMode = true;
break;
}
will give you a byte containing the first two bits, with the remaining bits zero-filled.
This works because 0x03 is
00000011in binary, andAND
zeroes the first six bits, leaving only the remaining two bits.