bit-wise manipulation Flashcards
x^0s ^ = XOR
x XOR with 0s leave 0s equal to zero and ones equal to one
x^1s
NOT X
x^x
0s
x & 0s
0s
x & 1s
X
x & x
x
x | 0s
x
x | 1s
1s
x | x
x
What is the difference between the arithmetic shift «_space;and the logic shift «
they are similar, they shift to the left or right the bits. The arithmetic one though keeps the same most significant digits, the logic one substitute that with zeros.
Get Bit i operation?
create a mask 1«i></i> then apply AND with number and see if the results is the zero or not
clear bits
mask of 11110111 with not i«i></i> then you apply an end
clever way to create a mask 000011111
generates a mask 000010000 with 1«i></i> then substract one
set a bit equal to one
simply use the mask 00010000 with i«i></i>
set a bit to some input value
You first clear by doing a non(i«i></i>) so you and this with the input then if v is your input value you or the results with v«i></i>