Skip to content

Instantly share code, notes, and snippets.

@paulononaka
Created April 7, 2011 17:22
Show Gist options
  • Save paulononaka/908246 to your computer and use it in GitHub Desktop.
Save paulononaka/908246 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;
}
@opnchaudhary
Copy link

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment