Currently I am working on socket programming where I have to send array of bytes to the firmware.The below code is for converting int into byte array.
public static byte[] intToFourByteArray(int value) {
return new byte[]{
(byte) (value),
(byte) (value >> 8),
(byte) (value >> 16),
(byte) (value >> 24)};
}
Can anyone make me understand how this right shift works,with small example.
and this is the oposite converting byte into int.
public static int byteArrayToInt(byte[] b) {
return b[0] & 0xFF
| (b[1] & 0xFF) << 8
| (b[2] & 0xFF) << 16
| (b[3] & 0xFF) << 24;
}
How this left shift and right shift works.