Skip to content

Instantly share code, notes, and snippets.

@vittodevit
Created October 6, 2020 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vittodevit/c6f0cfbfbc205c1bd53264e01353ca05 to your computer and use it in GitHub Desktop.
Save vittodevit/c6f0cfbfbc205c1bd53264e01353ca05 to your computer and use it in GitHub Desktop.
Converts int into little-endian 4 byte array
/**
* 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