Last active
April 9, 2025 00:42
-
-
Save valentyn-zaitsev/f2f1552fad526e0b1a3f0d2371831c67 to your computer and use it in GitHub Desktop.
Int to Byte array (java)
This file contains hidden or 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
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