How do you convert between binary, decimal, and hexadecimal?
To convert between binary, decimal, and hexadecimal, you translate the "place value" of the digits based on the number system's base. Decimal uses base 10, binary uses base 2, and hexadecimal uses base 16. You can think of these bases like different currencies. The value of your money doesn't change, but the way you count it out does. If you understand how much a "coin" is worth in a specific base, you can easily exchange it into any other base.
For binary to decimal, you add up powers of 2. For decimal to binary, you subtract the largest powers of 2 you can. Hexadecimal serves as a convenient bridge: because 16 is a power of 2 (), you can convert between binary and hexadecimal instantly by grouping binary digits into chunks of four.
Understanding Place Values
In our everyday decimal system (base 10), each place is a power of 10: the 1s place, 10s place, 100s place, and so on. Binary (base 2) works exactly the same way, but the "slots" are powers of 2. Reading from right to left, the places are 1, 2, 4, 8, 16, 32, etc.
To convert binary to decimal, simply write the binary number and add the place values wherever there is a 1. For example, the binary number has a 1 in the eights place, a 0 in the fours place, a 1 in the twos place, and a 1 in the ones place. . To go backwards from decimal to binary, find the largest power of 2 that fits into your number, subtract it, and place a 1 in that column. Repeat with the remainder until you hit 0.
The Magic of Hexadecimal
Hexadecimal (base 16) has 16 possible values per digit. We use 0-9 for the first ten values, but we need single symbols for 10 through 15. We borrow letters: A=10, B=11, C=12, D=13, E=14, and F=15.
Hexadecimal is popular in computer science because it is a perfect shorthand for binary. It takes exactly four binary digits (bits) to represent one hexadecimal digit. The maximum value of 4 bits () is , which is exactly 'F' in hexadecimal.
The Grouping Shortcut (Binary to Hex)
Because of this perfect match, converting between binary and hex doesn't require any complex math. You just group the binary bits into fours, starting from the right (the least significant bit).
If your binary number is , group it from the right: and . Pad the left group with leading zeros to make it four bits: and . Then translate each group independently. is 3, and is 5. So, the hex value is . To go from hex to binary, just reverse the process by writing out the 4-bit binary sequence for each hex digit.
Where Students Slip
The most common mistake when converting binary to hex is grouping from the left side instead of the right. If you group from the left as and , and pad the right with zeros, you completely change the value of the number.
Another frequent slip is forgetting that place values start at the 0th power (). Some students mistakenly start counting their place values at 2. Always remember that the furthest right column is the 1s place in every standard number base.
Worked through
Convert the binary number into decimal and hexadecimal.
1. Binary to Decimal: Write out the place values from right to left, starting with 1, doubling each time: 32, 16, 8, 4, 2, 1. Match them to the binary digits: . Add the values where the bit is 1: . The decimal value is .
2. Binary to Hexadecimal: Group the bits into sets of four, starting from the right: and . Pad the left side with zeros to complete the group: and . Convert each group to decimal/hex independently: . . In hex, 14 is represented by 'E'. Combine the results: .
Questions students ask
Ask about this topic
Where this comes from: Khan Academy: Computers and the Internet (Digital Information) · OpenStax: Introduction to Python Programming (Data Representation)
See also