Forked from paulononaka/JavaIntToLittleEndianUnsigned
Created
November 10, 2020 13:05
-
-
Save itsmefox/040e4a32d3f13fd3cce1e3e743e6b5ad to your computer and use it in GitHub Desktop.
Convert a Int (in Java, big endian signed) to LittleEndian unsigned
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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