I have found this piece of code that I have posted below that should convert bytes to integers, however I do not fully understand how this piece of code works in java. I believe bytebuffer is used in this case in a full piece of code as it is just a part I am struggling to understand.
public static byte[] intToBytes(int i) {
return new byte[] {
(byte) ((i & 0x000000FF) >> 0),
(byte) ((i & 0x0000FF00) >> 8),
(byte) ((i & 0x00FF0000) >> 16),
(byte) ((i & 0xFF000000) >> 24)
};
public static int bytesToInt(byte[] bytes) {
return ByteBuffer.wrap(bytes).getInt();
}
User contributions licensed under CC BY-SA 3.0