Possible Duplicate:
Good tutorials on Bitwise operations in Java
Are the &, |, ^ bitwise operators or logical operators?
Code as below:
int rgb[] = new int[] {
(argb >> 16) & 0xff, //red
(argb >> 8) & 0xff, //green
(argb ) & 0xff //blue
};
I saw a code which is getting RGB value from a INT value, the operations are as above, but I never see such operation before, I want to find more information about what are they and what can they do, The symbol >> and & and 0xff.
So, what do you all address them in Java?
Further explanation of the bit arithmetic. Let’s assume the int bits look as follows:
To get the int value for blue, you want all bits other than the lower 8 turned off. The easy way to do this is with a bitwise and. 0xff can also be written as 0x000000ff, which will set the upper 24 bits to 0, and only turn on the bits in the lower 8 which are already set to 1.
even thought the & 0xff on the red value seems unecessary, there’s no guarantee the caller might not have set some of the high order unused bits, so you want to be safe and turn all of them off.