Created
October 6, 2020 19:09
-
-
Save vittodevit/c6f0cfbfbc205c1bd53264e01353ca05 to your computer and use it in GitHub Desktop.
Converts int into little-endian 4 byte array
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
/** | |
* Converts an int to a byte[] | |
* @param i Integer to convert | |
* @return byte[] | |
*/ | |
public static byte[] intToByteArray (int i) { | |
ByteBuffer buf = ByteBuffer.allocate(4); | |
buf.order(ByteOrder.LITTLE_ENDIAN); | |
buf.putInt(i); | |
return buf.array(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment