Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save itsmefox/040e4a32d3f13fd3cce1e3e743e6b5ad to your computer and use it in GitHub Desktop.
Save itsmefox/040e4a32d3f13fd3cce1e3e743e6b5ad to your computer and use it in GitHub Desktop.
Convert a Int (in Java, big endian signed) to LittleEndian unsigned
private static byte[] intToLittleEndian(long numero) {
ByteBuffer bb = ByteBuffer.allocate(4);
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.putInt((int) numero);
return bb.array();
}
// OR ...
private static byte[] intToLittleEndian(long numero) {
byte[] b = new byte[4];
b[0] = (byte) (numero & 0xFF);
b[1] = (byte) ((numero >> 8) & 0xFF);
b[2] = (byte) ((numero >> 16) & 0xFF);
b[3] = (byte) ((numero >> 24) & 0xFF);
return b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment