Published on: March 28, 2016 Last Updated: April 8, 2018 Category: Code

It is possible to represent an IPv4 address in different formats than the common x.x.x.x notation. An IPv4 address is simply a 32-bit number, or a 4-byte number with each section representing a byte.

For example using my mkaz.com IP address: 45.79.78.169

Converting each part to binary:

Decimal Binary Hex
45 00101101 2D
79 01001111 4F
78 01001110 4E
169 10101001 A9

All together the binary number would be: 00101101010011110100111010101001

Converting the full number to the decimal works as http://760172201/

You can also use the hexadecimal prefixing with 0x: http://0x2D4F4EA9/

To convert a standard IP address to a single decimal, use the formula:

`a.b.c.d = (a * 256^3) + (b * 256^2) + (c * 256^1) + (d * 256^0)`

For above example, showing my work:

``````(45 * 256^3) + (79 * 256^2) + (78 * 256^1) + (169 * 256^0)
(45 * 16777216) + (79 * 65536) + (78 * 256) + (169 *1)
754974720 + 5177344 + 19968 + 169
760172201
``````

As expected, giving the same number above.

### Python Functions

The python REPL makes it relatively easy to do the quick conversions. For reference, here are the Python functions I used to help convert from different numerical bases.

Convert decimal to binary:

``````>>> bin(45)
'0b101101'
``````

Convert decimal to hex:

``````>>> hex(45)
'0x2d'
``````

Convert binary to decimal:

``````>>> print( int('00101101010011110100111010101001', 2) );
760172201
``````