Binary Numbaz Act II

Converting Binary to Hexadecimal…

1 10 – A

211 – B

3 12 – C

4 13 – D

514 – E

615 – F

7

8

9

Hex F E D C B A 9 8 7 6 5 4 3 2 1
Binary 1111 1110 1101 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001

First of all, you must understand a common convention in hexadecimal notation. You’ll typically see hexadecimal numbers preceded by 0x, it just means that the number is hexadecimal, but the actual 0x is irrelevant to the number. So 0×42FE means that 42FE is a hexadecimal number, we know that because of the 0x, but again, ignore the 0x when you’re actually working with the number.

To convert from binary to hexadecimal is very easy, you first separate the binary number into nibble (4 bits). For example, the number 24, which is 00011000 in binary, you would set it up as 0001 1000. Then, what you do, is you convert each nibble into decimal, for example, for the first nibble, 0001, since it equals one in decimal, you would then convert the decimal into hexadecimal, and since in hex 1 is 1, you would write 1. Now, for the second nibble, 1000, in decimal is 8, and in hex its 8, so 0001 1000 in hexadecimal is 0×18.

Lets do another one, the number 224 which is 11100000 in binary, would be 1110 0000. The first nibble, 1110, in decimal is 14. So you would see what 14 is in hexadecimal, 14 in hex is E. Now the second nibble is 0000, so in decimal its 0, and in hex its 0. The final number in hex would be 0xE0.

To convert from hexadecimal to binary, all you do is get the number, for example, 0xE0, that we did in the last example. We then read from left to right, or right to left, it doesn’t matter, as long as we maintain the order. So lets do it from right to left, since I know most of you would say that, okay, the first digit is 0, and in binary 0 is 0000. Note that each digit in hexadecimal is 4 bits, so even though we can express 0 in 000000, and also 0, we have to fill up 4 bits, so it would be 0000. The next digit, which is E, in decimal is 14, so in binary it would be:

 14
- 8 <----Using an eight.
---
  6
- 4 <----Using a four
---
  2
- 2 <----Using a 2
---
  0

Since we are using nibbles, we only need four bits, so:

8 | 4 | 2 | 1
1   1   1   0

I know that finding out 14 in binary was very easy, but I just did the whole thing so that others could understand the process.

So 0xE0 in binary is 1110 0000. Note that we converted the hex number from right to left, so we write it the same way, right to left. We found out the 0000 first, so we put it on the right, and we work our way to the left, in this case, 1110, which is 14. So again, the answer is 1110 0000.

To convert from hexadecimal to decimal, don’t be tempted to just do the following:

Considering 0xE0, you would say, okay, from right to left. 0 in decimal is 0. And E in decimal in 14, so you’d think the answer is 140. WRONG! Please remember the right way to do it. First, you convert it to binary, and from the last example, we found out its 1110 0000. okay, now you set up the columns, unless your a master a binary:

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

So it’s 128 plus 64 plus 32, in other words, its the hexadecimal number in binary, to decimal. That would make 224

~ by spamnrice on December 16, 2008.

Leave a Reply