2018年3月29日 星期四

Bit wise

OperationResultSame asResult
5 & 110101 & 0001 0001
5 | 150101 | 0001 0101
~ 510 ~0101 1010
5 << 1100101 << 1 1010
5 ^ 140101 ^ 0001 0100
5 >> 120101 >> 1 0010
5 >>> 120101 >>> 1 0010
OperatorNameDescription
&ANDSets each bit to 1 if both bits are 1
|ORSets each bit to 1 if one of two bits is 1
^XORSets each bit to 1 if only one of two bits is 1
~NOTInverts all the bits
<<Zero fill left shiftShifts left by pushing zeros in from the right and let the leftmost bits fall off
>>Signed right shiftShifts right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off
>>>Zero fill right shiftShifts right by pushing zeros in from the left, and let the rightmost bits fall off

沒有留言:

張貼留言