I have an int which contains an IP address in network byte order, which I would like to convert to an InetAddress object. I see that there is an <
int
InetAddress
public static byte[] int32toBytes(int hex) { byte[] b = new byte[4]; b[0] = (byte) ((hex & 0xFF000000) >> 24); b[1] = (byte) ((hex & 0x00FF0000) >> 16); b[2] = (byte) ((hex & 0x0000FF00) >> 8); b[3] = (byte) (hex & 0x000000FF); return b; }
you can use this function to turn int to bytes;