In the following code:
short = ((byte2 << 8) | (byte1 & 0xFF))
What is the purpose of &0xFF
?
Because other somes
Assuming your byte1
is a byte(8bits), When you do a bitwise AND of a byte with 0xFF, you are getting the same byte.
So byte1
is the same as byte1 & 0xFF
Say byte1
is 01001101
, then byte1 & 0xFF = 01001101 & 11111111 = 01001101 = byte1
If byte1 is of some other type say integer of 4 bytes, bitwise AND with 0xFF leaves you with least significant byte(8 bits) of the byte1.