I have a byte array that contains 6 bytes last 2 represents the port number while searching for a way two convert these last to bytes to a port number i have come across this snippet,
int port = 0;
port |= peerList[i+4] & 0xFF;
port <<= 8;
port |= peerList[i+5] & 0xFF;
it works but i need some clarification as to how it works?
Basically, it takes byte #5, shift is 8 bits to the left resulting in
0101010100000000and then uses the bitwise or operator to put the byte 6 in the place of zeros.