The TERSCH.com Project... Logo and Image Map

Navigation Links Image Map

How to Convert Between Numerical Formats

 

Binary to Hexadecimal: To convert a binary number, such as 10110100, (which is 180 in decimal format) to hexadecimal, just break it down into four-digit (bit) blocks: 1011 0100. Then just transfer each four-bit block into its decimal counterpart: 11 and 4. Finally, convert each decimal number into its hex version: B and 4. So your number in hex is B4. In this way, you only need to know the first 15 hexadecimal numbers.

Hexadecimal to Binary: Start with a hexadecimal number, such as B4. Break it up into its two parts, B and 4. Then, assuming that you know the first 15 hexadecimal numbers and their decimal equivalents, convert B to 11, and 4 to 4. Then, change these decimal numbers into their binary equivalents. 11 is equal to 1011, and 4 is equal to 0100. Then, just put together these two new four-bit binary numbers, to have your binary answer, 10110100.

Decimal to Binary: Take a decimal number, for example 57, and, using a chart of binary number values, find the closest binary number value that doesn't go over the decimal number you're working with. In this case, 32 is what you're looking for, and it falls on the 6th from rightmost bit in a binary number. So you so far have 001 (working from left to right in an 8-bit binary number), since the 'switches' for 128 and 64 are 'off'. Those two numbers won't fit into 57. Then subtract 32, since its 'switch' is 'on', from the original number of 57. This gives you a new answer of 25. Once again, look for the closest binary bit value that doesn't go over. In this case, it's 16, which is on the 5th from rightmost binary bit. So, adding this 'on' switch to your binary number, you now have 0011. But these steps need to be done again. 25 minus 16 still equals 9. Make the bit representing 8 'on', giving you 00111, and subtracting an additional 8 from your current decimal number. You have only 1 remaining. And in binary, the bit which has a value of 1 is the 1st bit. The bits with values of 4 and 2 are too large, so you put those as zeroes, 'off', and 'turn on' the bit for 1, the last and final bit. So your final binary answer is 00111001. (Here's how: 0 + 0 + 32 + 16 + 8 + 0 + 0 + 1 = 57.) (Note: all of the values of binary bits are two times the previous, or next, depending on which way you're reading from, number, because binary is a base 2 number system.)

Decimal to Hexadecimal: For this example we will use the decimal number 99. Because 99 is less than or equal to 255, we will use the equation n = 16x + y, where n equals your original decimal number, and your final hex number answer is in the form xy. (For converting decimal numbers of 256 to 4095, 'n = 256x + 16y + z' is used. And for numbers between 4096 and 65536, use 'n = 4096w + 256x + 16y + z'. This trend continues, with a new first term that is 16 times the prior first term, being added to the equation. Your final hex answer is exactly the variables, in their original order.) So we have 99 = 16x + y. Now it's just a matter of finding the x value that will bring you closest to 99 without going over; this is not entirely unlike the way that we previously looked for binary number bit values. In this instance, the largest correct x value is 6. We substitute in for x, so our equation is now 99 = 16(6) + y. Just like any ordinary equation, we now only need to multiply 16 times 6, which equals 96, then subtract 96 from both sides. The equation now simply reads 3 = y, which answers the second part of the problem, which is to find the value of y which would balance the equation. And because your final hex number is in the form xy, we just substitute in 6 and 3, which are the same in decimal and hex formats, so we don't need to change them to, well, the letter E for example. Because their form is together, but not multiplied by each other, your final answer is 63, which is exactly 99 in hexadecimal format. (Note: the reason that the coefficients of the variables are multiples of 16 is because hexadecimal numerology is a base 16 system.)

Hexadecimal to Decimal: Basically, this is just a matter of doing all the steps above in reverse order. Start by breaking up your hex number, for example, 2E, into individual digits, so 2 and E. Convert these into their decimal counterparts, namely 2 and 14, respectively. You then only need to substitute these numbers into the equation 'n = 16x + y' to have 'n = 16(2) + 14', which is equal to 46 in decimal format. (And a final side note: in decimal format, which we humans use almost always, each next, less rightmost, digit has a value of 10, since Decimal is a base 10 number system.)

Binary to Decimal: Start with a binary number like 00010010. Then just use the equation N = 2n, where n represents the decimal value for that particular 1 in the binary number, and n is the number of digits that the binary decimal place (where the 1 is) in question is from the rightmost, smallest digit, with the rightmost digit having an n value of zero. This means that, in our example, the rightmost 1 is also 1 digit from the rightmost binary bit decimal place. Meaning, we substitute in to get N = 21, or N = 2. So the decimal value for that particular, rightmost 1, is 2. We then repeat this for the other 1 present our example binary number, to have N = 2 4, or N = 16. We then just add up our values of 16 and 2 to get 18, the decimal value for the binary number 00010010.

 

Plagiarism warning: Please read!

Navigation Image Map