Network Addressing

Integer to IPv4

Direction
32-bit integer
IPv4 address 192.168.1.1
Unpack four bytes from 32 bits
Octets 192 · 168 · 1 · 1
Hexadecimal 0xC0A80101
Binary, by octet 11000000 10101000 00000001 00000001
Integer 3232235777
Note
Four shift-and-mask operations
Advertisement
320 × 100

Unpack the 32-bit integer into four bytes, most significant first. 3232235777 becomes 192.168.1.1. Anything above 4294967295 is out of range for IPv4.

How to convert an integer to an IP

1 Enter the integer.
2 Read the dotted-quad address.
3 Check the binary row to see the octet boundaries.
4 Values outside 0 to 4294967295 are rejected.

The unpacking is four shift-and-mask operations: shift right by 24, 16, 8 and 0, masking each with 255. Seeing it written that way makes the structure obvious — the address really is one number, and the octets are just four slices of it. It also explains why the byte order matters: reading the slices in the wrong direction gives 1.1.168.192, a perfectly valid but entirely different address.

Questions

192.168.1.1.

Advertisement
300 × 250
Was this tool any good?
INTERNAL SIGNAL ONLY · WE USE IT TO FIND TOOLS WORTH REBUILDING