Reputation: 31
I am trying to bitshift like this in order. Is there a logical operation that can help me do this?
0111 1111
1011 1111
1101 1111
1110 1111
1111 0111
1111 1011
1111 1101
1111 1110
For hexadecimal, it would be
0x7F
0xBF
0xDF
0xEF
0xF7
0xFB
0xFD
0xFE
Upvotes: 2
Views: 323
Reputation: 481
Try this for 8 bit numbers (example works for Java, may be helpful for С too)
value = ((value >> 1) & 0x7F) | 0x80
And this one for back propagation of zero
value = ((value << 1) | 1) & 0xFF
Upvotes: 3