How to Convert Between Binary, Decimal and Hexadecimal

Why does the binary number 10 equal two, not ten? The answer is place value, and once you see it, every base conversion gets easier.

Quick Answer

To convert between number bases, use place value. For binary to decimal, add the powers of two where a 1 appears. For decimal to binary, divide by 2 again and again, then read the remainders from last to first. Hex is shorthand: each hex digit equals exactly four bits.

Place Value Is the Idea Behind Every Base

Every number base runs on place value. A digit’s worth depends on where it sits, and each step to the left multiplies the weight by the base. Decimal, or base 10, is the system most of us use every day.

In 352, the 3 means 300 because it sits in the hundreds place. The weights are 1, 10 and 100, which are powers of ten.

Binary is base 2 and uses only two symbols, 0 and 1. Each digit is a bit, short for binary digit. Almost all computers use it because it is easier to build in electronic circuits. Hex is base 16, with the digits 0 to 9 and then A to F.

One standard rule covers every base: the value is the sum of each digit times the base raised to its position, counting positions from 0 at the right. So binary 10 is 1 x 2 + 0 x 1, which is 2. You can check any answer in this guide with the base converter.

Binary to Decimal by Adding Powers of Two

To turn binary into decimal, write the weights 1, 2, 4, 8 and so on under the bits, starting at the right. Then add only the weights that sit under a 1. Those weights are powers of two, and our guide to exponents and scientific notation shows how powers grow.

Take 101010. The weights from left to right are 32, 16, 8, 4, 2 and 1. The 1s sit under 32, 8 and 2, so the total is 32 + 8 + 2 = 42.

Binary 101010 as place values Six boxes in a row hold the bits 1, 0, 1, 0, 1, 0. Above them are the weights 32, 16, 8, 4, 2 and 1. The boxes with a 1 are colored, and a bar below adds their weights: 32 plus 8 plus 2 equals 42. Add the weights that sit under a 1 32 16 8 4 2 1 1 0 1 0 1 0 2^5 2^4 2^3 2^2 2^1 2^0 32 + 8 + 2 = 42
Only the boxes holding a 1 add their weight to the total.

A shorter example shows the pattern again. Binary 11001 has weights 16, 8, 4, 2 and 1. The 1s sit under 16, 8 and 1, so the total is 16 + 8 + 1 = 25.

The same method works for any length. The biggest value that fits in 8 bits is 11111111, which is 255, or 2^8 – 1. Smaller still, 1111 is 8 + 4 + 2 + 1, which is 15.

Decimal to Binary by Repeated Division

To turn decimal into binary, divide by 2 over and over and write down each remainder. Stop when the quotient reaches 0. Then read the remainders from last to first. This is a standard method that works for any whole number.

Here is 42. Divide 42 by 2 and you get 21 with remainder 0. The next steps give 10 r1, then 5 r0, then 2 r1, then 1 r0, and finally 0 r1.

Repeated division of 42 by 2 Six rows show the divisions: 42 divided by 2 is 21, 21 divided by 2 is 10, 10 divided by 2 is 5, 5 divided by 2 is 2, 2 divided by 2 is 1, and 1 divided by 2 is 0. Remainder boxes beside each row read 0, 1, 0, 1, 0, 1. An arrow points upward, showing the remainders are read from the bottom to the top, giving 101010. Divide by 2, keep the remainder, repeat until 0 Division Remainder 42 / 2 = 21 21 / 2 = 10 10 / 2 = 5 5 / 2 = 2 2 / 2 = 1 1 / 2 = 0 0 1 0 1 0 1 Read upward Last to first 101010 binary for 42
The last remainder becomes the leftmost bit, so you read the column from the bottom.

Always check by adding back. The weights 32 + 8 + 2 give 42, which matches the number you started with.

Reading the remainders top to bottom gives 010101, which is only 21. The same method works in any base. To reach hex, divide 491 by 16: 491 / 16 = 30 remainder 11, which is B. Then 30 / 16 = 1 remainder 14, which is E, and 1 / 16 = 0 remainder 1. Read upward and you get 1EB.

Hex as Shorthand for Four Bits

One hex digit stands for exactly four bits, a group called a nibble. Because 16 is a power of 2, hex packs binary data into a dense, readable form.

Hex uses the digits 0 to 9, then the letters A to F for the values 10 to 15. The letters can be upper or lower case. Each digit maps to one four-bit pattern.

Hex digits A to F with their decimal values and four-bit patterns
Hex digit Decimal value Four bits
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111

The digits 0 to 9 keep their value and pad to four bits, so 0 is 0000 and 9 is 1001. An 8-bit byte is two hex digits, such as 2C. Our bits vs bytes guide covers how those sizes fit together.

Writers mark hex so it is not mistaken for decimal. C-style languages use the prefix 0x, as in 0x1EB. Hex also appears in web colors, which our hex color codes guide explains on its own.

Hex to Binary and Back by Digit Groups

To convert hex to binary, swap each hex digit for its four-bit pattern. To go the other way, group the bits in fours from the right, then swap each group for a hex digit.

Take 1A3F. The digit 1 is 0001, A is 1010, 3 is 0011 and F is 1111. Joined together they read 0001 1010 0011 1111, and dropping the leading zeros leaves 1101000111111.

Hex 1A3F as four-bit groups Four navy blocks hold the hex digits 1, A, 3 and F with their decimal values 1, 10, 3 and 15. Each connects down to a four-bit block: 0001, 1010, 0011 and 1111. A line below joins the groups and drops the leading zeros to give 1101000111111. One hex digit becomes one group of four bits 1 A 3 F value 1 value 10 value 3 value 15 0001 1010 0011 1111 Joined, with leading zeros dropped: 1101000111111
Each hex digit expands to its own four-bit group, with no carrying between groups.

For the decimal value, use place value with weights 1, 16, 256 and 4,096. So 1A3F is 1 x 4096 + 10 x 256 + 3 x 16 + 15, or 4096 + 2560 + 48 + 15 = 6,719.

Going back, try 101111. Group from the right as 10 and 1111. Pad the left group to 0010, and the groups read 2 and F. The hex number is 2F, which is 2 x 16 + 15 = 47.

Octal and a Quick Reference Table

Octal is base 8, and each octal digit equals three bits. Group the bits in threes from the right. For 42, binary 101010 splits into 101 and 010, which are 5 and 2, so octal 52 is 5 x 8 + 2 = 42.

Octal also works in reverse. Octal 377 becomes 011 111 111, which is binary 11111111, or 255 in decimal. It appears less often than hex, but the idea is the same: one digit for each fixed group of bits.

Six values in decimal, binary, octal and hex
Decimal Binary Octal Hex
10 1010 12 A
16 10000 20 10
42 101010 52 2A
100 1100100 144 64
255 11111111 377 FF
1024 10000000000 2000 400

Two rows are worth remembering. FF is 15 x 16 + 15 = 255, the largest 8-bit value. And 1024 is 2^10, so its binary form is a 1 followed by ten zeros.

Common Mistakes and Tool Limits

Most conversion errors come from a few repeat slips. Watch for these as you work.

  • Reading 10 in binary as ten. It equals 2.
  • Using a digit the base does not allow, such as 2 in binary or 9 in octal.
  • Reading remainders in the wrong order. Always go from last to first.
  • Losing leading zeros inside a group. Keep 0011 as four bits until you finish, and do not mix up B (11) with 8.
  • Skipping the base marker. Write 0x1EB or a subscript so the base is clear.

The base converter takes whole, non-negative numbers only. It rejects an invalid digit such as binary 102, a negative sign, or a decimal point like 3.5. The largest exact value is 9,007,199,254,740,991, which is 2^53 – 1. A number such as 9,007,199,254,740,993 is reported as too large to convert exactly.

If powers still feel slippery, see our guide to powers, roots and reciprocals.

Want to check your own numbers?

Type a value in any base into the base converter and see the decimal, binary, octal and hex forms at once.

FAQs About Number Base Conversion

What is 101010 in decimal?

It is 42. Add the weights under each 1: 32 + 8 + 2 = 42. The other three bits are zeros, so they add nothing.

How many bits is one hex digit?

One hex digit is exactly four bits, called a nibble. Two hex digits make an 8-bit byte, such as 2C.

Why do computers use binary?

Binary uses only two symbols, 0 and 1, which is easier to build in electronic circuits. Almost all computers and electronic devices use it.

What does the 0x prefix mean?

In C-style languages, 0x marks a number as hex. For example, 0x1EB is the hex number 1EB, which equals 491 in decimal.

Why is FF equal to 255?

F is 15, so FF is 15 x 16 + 15 = 255. It is also the largest value that fits in 8 bits, which is 2^8 – 1.

Can the base converter handle negatives or decimals?

No. It handles whole, non-negative numbers only. A negative sign or a decimal point like 3.5 is rejected as invalid.

In which order do I read the division remainders?

Read them from last to first, bottom to top. For 42 the remainders come out as 0, 1, 0, 1, 0, 1, so you read 101010.

Sources and Further Reading

References Used in This Article

This article is a general math and computing guide. Check your course or language documentation for notation rules. Reviewed for accuracy by Prof. Dr. Khalil Mudassar, PhD. Last updated 2026-10-15.


Author

shakeel-Muzaffar
Founder & Editor-in-Chief at  ~ Web ~ More Posts

Shakeel is the Founder and Editor-in-Chief of MultiCalculators.com, with over 15 years of experience in digital publishing and online tool development. He oversees editorial quality, formula accuracy, and usability to ensure the platform delivers reliable, practical calculators for users worldwide.