Binary, Hexadecimal, Decimal

Alisher Fayzimatov
3 min readFeb 12, 2020

--

When you are counting binary numbers you are always counting where the number is 1. Also, when converting to decimal, the numbers will always increase starting from 1, then it adds to itself ie; 1 to 1 = 2 , then 2 to 2 = 4 etc,.

Also, please note that binary comes in base of 2, decimal is base of 10, and hexadecimal is base of 16

Converting hexadecimal to decimal

Hexadecimal 4A5

4A5 = (4 * 16²) + (10 * 16¹) + (5*16⁰)

4A5 = (4 * 256) + (10 * 16) + (5 * 1)

4A5 = (1024) + (160) + (5)

4A5 = 1189 base 10 (base 10 is a way of letting others know that this is decimal)

Converting from decimal to hexadecimal

This isn’t difficult, and it can be approached from two different angles.

You can convert the decimal into binary, then turn the binary into hexadecimal

example; (I did this a lot in the past, but it will eat up your time)

Converting 402 to binary, then to hexadecimal.

We take our initial value of 402 and subtract from left to right, we begin from 256 since it’s smaller than 512,

which would be too big to subtract from 402.

256 128 64 32 16 8 4 2 1

402–256 = 146

146–128 = 18

18–16 = 2

2–2 = 0

Now we place a 1 to every number we used to subtract from 402 and 0 to every other number we skipped

1 — -1 — 0 — 0 — 1-00-10

256 128 64 32 16 8 4 2 1

So our binary number is 110010010, now we separate them into groups of 4, giving us 0001 1001 0010

You might be wondering why the three 0’s appeared in front of 1, since there are no values to be subtracted from 402 ahead of 256, it will be given a standard of 0

0001 1001 0010 in hexadecimal is, 192 base 16

The other choice would be to convert from directly from decimal to hexadecimal

Since 402 is greater than 16, we will divide by 16

402 / 16 = 25.125

Afterwards you take the remainder and multiply it by 16

.125 * 16 = 2

Then you take the whole number 25 and divide it by 16

25 / 16 = 1.5625

Multiply the remainder

.5625 * 16 = 9

Since the remaining whole number is 1, it’s not necessary to repeat the steps above

In the case of hexadecimal, you take the last remaining number and align it from bottom to top, giving you 1 9 2 base 16

--

--