Hexadecimal to Decimal and Binary

In the networking universe we use binary, decimal and hexadecimal values. Two good examples where we use hexadecimal values are MAC addresses and IPv6 addresses.

Especially for IPv6 addresses it’s useful to understand how you can calculate from hexadecimal to binary and decimal or the other way around.

In the decimal system we count from 0-10, in the hexadecimal system we count from 0 – F. Here’s an example:

Decimal Hexadecimal
 1  1
 2  2
 3  3
 4  4
 5  5
 6  6
 7  7
 8  8
 9  9
10 A
11 B
12 C
13 D
14 E
15 F

That’s not so bad right? Now if you want to calculate from binary to hexadecimal there’s a trick you need to master. Let’s say you have the decimal number 255 in binary:

128 64 32 16 8 4 2 1
1 1 1 1 1 1 1 1

If you want to convert this to hexadecimal you need to cut the 8 bits in two parts of 4 bits (4 bits is also known as a nibble).

First nibble:

1 1 1 1

Second nibble:

1 1 1 1

Now convert these nibbles from binary to decimal:

8 4 2 1
1 1 1 1

Both nibbles look the same: 8 + 4 + 2 + 1 = 15

Now take a look at the decimal-to-hexadecimal chart and you’ll see that 15 in decimal is equal to “F” in hexadecimal.

So the hexadecimal value = FF. Normally you see hexadecimal values written as 0xFF. If you see “0x”then  you know it’s a hexadecimal value.

Let’s try another decimal value and calculate it into hexadecimal, for example 118. First we convert 118 to binary:

128 64 32 16 8 4 2 1
0 1 1 1 0 1 1 0

64 + 32 + 16 + 4 + 2 = 118

We’ll chop our 8 bits into two nibbles and this is what we get:

First nibble:

0 1 1 1

Second nibble:

0 1 1 0

Now let’s convert these nibbles from binary to decimal:

8 4 2 1
0 1 1 1

The first nibble will be 4 + 2 + 1 = 7. The decimal value 7 is the same in hexadecimal.

8 4 2 1
0 1 1 0

The second nibble will be 4+2 = 6. The decimal value 6 is the same in hexadecimal.

Our hexadecimal value will be 0x76. Let’s try one more!

Let’s say we have the decimal value 206. In binary it looks like this:

128 64 32 16 8 4 2 1
1 1 0 0 1 1 1 0

128 + 64 + 8 + 4 + 2 = 206.

We’ll chop our 8 bits into two nibbles and this is what we get:

First nibble:

1 1 0 0

Second nibble:

1 1 1 0

Now let’s convert these nibbles from binary to decimal:

8 4 2 1
1 1 0 0

The first nibble will be 8 + 4 = 12. The decimal value 12 is C in hexadecimal.

8 4 2 1
0 1 1 0

The second nibble will be 8 + 4 + 2 = 14. The decimal value 14 is E in hexadecimal.

Our hexadecimal value will be 0xCE.

I hope these examples have been useful to you. If yes, share it with your friends! If you have any questions feel free to leave a comment in our forum.

Tags:


Forum Replies

  1. We can’t, there is no such thing :slight_smile: IPv6 addresses are 128 bit and hexadecimal, IPv4 has 32 bit decimal addresses.

  2. Hi Rene,
    “In the decimal system we count from 1-10, in the hexadecimal system we count from 1 – F”
    should be “decimal 0-9, hexadecimal 0-F” :slight_smile:

  3. Hi Georgi,

    That is so true, especially for computers :wink: Just edited the post…thanks!

    Rene

  4. Hi Rene , I don’t understand how you convert nibbles binary to decimal,

3 more replies! Ask a question or join the discussion by visiting our Community Forum