Byte[] B = {1,2,20,108};
String stmp = java.lang.Integer.toHexString (B[n] & 0XFF)
In the 32-bit computer, the numbers are stored in 32 format, if it is a byte (8-bit) type of number, his high 24-bit inside are random numbers, low 8-bit
is the actual data. The parameter of the Java.lang.Integer.toHexString () method is an int (32-bit) type, and if you enter a byte (8-bit) type of number, the
The method will also consider the height of the number 24 as a valid bit, which will inevitably lead to errors, using & 0XFF operation, can be high 24 position 0 to avoid such errors
The occurrence
0xFF = 1111 1111 Low 8 bit is 1, high is 0
Therefore, the &0XFF can be set to the high position of the number is 0, low 8-bit unchanged
http://blog.csdn.net/guo_rui22/article/details/2826308
Necessity of 0XFF use in Java.lang.Integer.toHexString (B[n] & 0XFF)