Conversions
Converting Binary to Decimal to Hex.
Many computers can understand three types of codes: Decimal, Binary, and Hexadecimal. Each with a different base number system.
Decimal
Decimal number systems consist of numbers from 0-9. This is a base 10 number system.
Binary
Binary number systems consist of 0s and 1s. Since it has only two digits it is a base 2 number system.
Each digits is a bit. 4 bits together are called a "nybble". 8 numbers together are one byte or two nybbles.
Hexadecimal
Unlike decimal, hexadecimal has a base 16 number system. After 9, the numbers from 10-15 are substituted by letters A-F.
How to convert?
To convert each other, there's mathematical steps we have to take.
Binary to Decimal:
To convert from binary to decimal, you use the base 2 number system mentioned earlier.
From right to left, you write 2^0, 2^1, and onwards.
You multiply them by the corresponding digits, and then add them togther.
For example, 1001 is 1 x 2^0 + 0 x 2^1 + 0 x 2^2 + 1 x 2^3.
If you know bedmas, you do multiplication first, which leaves you with:
1 + 8 = 9.
Therefore, 1001 is 9.
Hex to Decimal
To convert from hex to decimal, you use the base 16 number system.
You read from right to left and write 16^0, 16^1, and onwards.
You multiply them by the corresponding digits, and then add them togther.
For example, 5A is 10 x 16^0 and 5 x 16^1.
Remember that A-F is 10-15. So A = 10.
The equation would be (10 x 1) + (5 x 16)
The equation is 10 + 80 = 90.
Decimal to Binary
To convert from decimal to binary, rather than multiplying as shown above, you use long division.
You keep diving the number by 2, and the remainders are either 1 or 0. Each remainder you get, you add that digit. Make sure to keep putting them from right to left.
Let's use 12 as an example.
Number |
12 |
6 |
3 |
1 |
Binary Digit (remainder) |
0 |
00 |
100 |
1100 |
An alternate way to do it is to remember the value of each position in binary.
For example, 1111. The total is 15. The value from right to left for each
placement is 1, 2, 4, and 8. With 8 digits, the numbers add up to 256.
And the numbers continue to 16, 32, 64, 128. All you have to do is place a "1" at the placements that add up to the decimal.
Let's use the number 45.
0 0 0 0 0 0 0 0
We can eliminate 64 and 128, since those numbesr are too high. But we can use 32.
0 0 1 0 0 0 0 0
Now 16 + 32 = 48. So it's too high. 32 + 8 + 4 + 1 = 45.
0 0 1 0 1 1 0 1 is the binary number for 45.
Decimal to Hex
To convert from decimal to hex, you use long division. Similar to decimal to binary.
Only this time, you keep dividing by 16. Whichever number the remainder is, you use it. Right them from right to left.
Let's use 128 as an example.
Number |
128 |
8 |
Hex Digit (remainder) |
0 |
80 |
Since the remainder was 8, the hex number would be 80.
Binary to Hex
To convert from binary to hex, you treat the two nybbles as seperate digits.
Since the maximum digit in maximum is F, the binary digit 1111 is the maximum of 15.
Let's use 1100 1011 as an example.
If you convert each to decimal, the nybbles are 12 and 11. The hex digits for both are C and B. Therefore, the hex digit for 1100 1011 is CB.
Hex to Binary
To convert from hex to binary, it is the same as above but reversed.
You put each hex digit as a nybble.
Let's use the hex digit 4A
4 in binary is 0100 and A (10) in binary is 1010.
Therefore, the binary digit would be 0100 1010.
Link To:
Home Page