Joshua Park
Joshua Park

Reputation: 31

How can I bitshift a 0 bit?

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

Answers (1)

Vitalii
Vitalii

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

Related Questions