AdSense

Wednesday, September 17, 2014

Binary numbers and shift operators

int x = 4;
Integer.toBinaryString(x) : 10;

int x = 4 (100) >> 1: right shift 1 position, 2 (10);
int x = 4 (100) << 1: left shift 1 position, 8 (1000);

~       Unary bitwise complement
<<      Signed left shift
>>      Signed right shift
>>>     Unsigned right shift
&       Bitwise AND
^       Bitwise exclusive OR
|       Bitwise inclusive OR

No comments:

Post a Comment