Skip to content

Instantly share code, notes, and snippets.

@valentyn-zaitsev
Last active April 9, 2025 00:42
Show Gist options
  • Save valentyn-zaitsev/f2f1552fad526e0b1a3f0d2371831c67 to your computer and use it in GitHub Desktop.
Save valentyn-zaitsev/f2f1552fad526e0b1a3f0d2371831c67 to your computer and use it in GitHub Desktop.
Int to Byte array (java)
public static final byte[] intToByteArray(int value) {
return new byte[] {
(byte)(value >>> 24),
(byte)(value >>> 16),
(byte)(value >>> 8),
(byte)value};
}
public static byte[] intToByteArray(int value) {
byte[] bytes = new byte[4];
ByteBuffer.wrap(bytes).putInt(value);
return bytes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment