List of utility methods to do Int to Byte Array Convert
String | int2hex(int i) inthex String h = ""; h = Integer.toHexString(i); if (h.length() == 1) { h = "0" + h; return h; |
int | intFitsIn(final int value) Check how many bytes is required to store value. if (value < 0) { return 4; if (value < (1 << 2 * 8)) { if (value < (1 << 1 * 8)) { return 1; return 2; ... |
int | intForByte(byte b) int For Byte int value = b & 0xFF; return value; |
byte[] | intToByte(int number) int To Byte int temp = number; byte[] b = new byte[4]; for (int i = 0; i < b.length; i++) { b[i] = new Integer(temp & 0xff).byteValue(); temp = temp >> 8; return b; |
byte[] | intToByteArray(int a) Converts an int to a 4 byte array. byte[] ret = new byte[4]; ret[3] = (byte) (a & 0xFF); ret[2] = (byte) ((a >> 8) & 0xFF); ret[1] = (byte) ((a >> 16) & 0xFF); ret[0] = (byte) ((a >> 24) & 0xFF); return ret; |
byte[] | intToByteArray(int i) int To Byte Array byte[] result = new byte[4]; result[0] = (byte) ((i >> 24) & 0xFF); result[1] = (byte) ((i >> 16) & 0xFF); result[2] = (byte) ((i >> 8) & 0xFF); result[3] = (byte) (i & 0xFF); return result; |
byte[] | intToByteArray(int value) int To Byte Array return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value }; |
byte[] | intToBytes(int i) Returns a byte array containing the bytes of the given integer in big endian order. return new byte[] { (byte) (i >> 24), (byte) (i >> 16 & 0xFF), (byte) (i >> 8 & 0xFF), (byte) (i & 0xFF) }; |
byte[] | intToBytes(int in) int To Bytes byte[] b; b = new byte[] { (byte) (in >>> 24 & 0xFF), (byte) (in >>> 16 & 0xFF), (byte) (in >>> 8 & 0xFF), (byte) (in >>> 0 & 0xFF) }; return b; |
byte[] | intToBytes(int n) int To Bytes byte[] b = new byte[4]; b[3] = (byte) (n >> 24); b[2] = (byte) (n >> 16); b[1] = (byte) (n >> 8); b[0] = (byte) (n >> 0); return b; |