Well, I believe you mean hexadecimal, not hexagon. Just like DECImal is base 10, BInary is base 2 and HEXADECImal is base 16. To convert by hand, you can convert binary to decimal, then decimal to hexadecimal.
For instance, 1011001 becomes 1*64 + 0*32 + 1*16 + 1*8 + 0*4 +0*2 +1*1 = 89.
Now we need to convert that to hexadecimal, so write out the the powers of 16: 16^0 = 1, 16^1 = 16, 16^2 = 256.
256 is larger than 89, so we only need two digits.
For the first digit:
16*1=16, 16*2=32, 16*3=48, 16*4=64, 16*5=80, 16*6=96.
96 is larger than 89, so the first digit (the 16^1 position) is 5.
Subtract 80 from 89 = 9.
16^0 = 1. 1*9 = 9. The second digit is 9
The hexadecimal equivalent is 59
Alternatively, (and faster) you can write out groups of four binary digits.
(Binary) = (Hexadecimal)
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000= 8
1001 = 9
1010 = A
1011 = B
1100 = C
1101 = D
1110 = E
1111 = F
Then segment the binary number into groups of four
(e.g. 10011010111001 becomes 10 0110 1011 1001 -- you can pad the first group with 2 zeroes to make it a group of 4)
and use the above mapping to turn that into 26B9.
Chat with our AI personalities
5
write a c++ program to convert binary number to decimal number by using while statement
All I know is that when a number is negative, you convert the decimal into binary and if it is negative you put 1111 before the binary digits.
Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equivalent?
Convert each hex digit to four binary digits. If you get less than three (for example, 7 --> 111), fill it out with zeroes to the left (in this case, 0111).