binary - Bit Manipulation: Set a bit to 0 in unknown number -


let's have binary number, 8 bits long. don't know is.

xxxx xxxx

i want set bit 4 0. how do this?

if knew values of x, go

xxxx xxxx , xxxx 0xxx

but don't know values of x. how can without knowing values?

thank you.

xxxx xxxx , 1111 0111 

the bitwise , operator here not "turn on" bits "off" on left; can "turn off" bits otherwise "on". guarantee bit 4 "off", regardless of input.

to elaborate:

1 , 1 => 1 0 , 1 => 0 1 , 0 => 0 0 , 0 => 0 

thus setting every bit "on" in number on right, you're guaranteeing either "stay on" or "stay off" -- i.e. won't changed. 1 set "off" on right, 1 always "off", no matter comes in on left.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -