The literal 11001010 represents a decimal of the int type and the values 11,001,010 are 11 million and something.
If you are using Java 7 , you can define binary literals using the 0b prefix, for example 0b11001010 . To improve readability, you can put underscores in values, such as 0b_1100_1010 .
However, note that the type of the even binary (or hexadecimal) literal is still int . This, together with the fact that bytes (unfortunately) are signed in Java (thus their value is in the range -128 to 127 ), leads to the fact that a literal with a value greater than 127 must manually byte :
// 0b_1001_0001 or 0x91 is 145 in decimal byte b1 = (byte) 0b_1001_0001; byte b2 = (byte) 0x91;
However, the value of such a byte will be -111 (145 - 256). To return an unsigned value, you need to manually add the module (256) to the value:
int i1 = b1 + 256; int i2 = b1 & 0xff;
See this question for more details.
Natix source share