How to Convert Binary to Decimal (and Hex): Step by Step
To convert binary to decimal, multiply each bit by its place value and add the results. The place values are powers of 2 that double from right to left: 1, 2, 4, 8, 16 and so on. For example, 1011 in binary is 1×8 + 0×4 + 1×2 + 1×1 = 8 + 0 + 2 + 1 = 11.
Try it free: Integer Base Converter Free to use, no account needed.
This guide shows how to convert binary to decimal with two methods, how to go the other way from decimal to binary, what hexadecimal is and why programmers use it, and how to switch between binary, hex and octal without a calculator. Every example below was checked with code. To check your own numbers as you read, paste them into the free Binary Converter.
How to read binary: place values
Binary code is information written with only two symbols, 0 and 1. Computers use it because their circuits work with two states, such as low and high voltage. Each binary digit is called a bit, and a group of 8 bits is a byte.
Binary is a positional system, just like decimal. In decimal, each position is worth 10 times the one to its right (ones, tens, hundreds). In binary, each position is worth 2 times the one to its right:
| Position (from the right) | 8th | 7th | 6th | 5th | 4th | 3rd | 2nd | 1st |
|---|---|---|---|---|---|---|---|---|
| Power of 2 | 2⁷ | 2⁶ | 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ |
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
A 1 means "include this place value" and a 0 means "skip it".
How to convert binary to decimal step by step
Method 1: add the place values
Take the binary number 11010110. Write the place values under the bits, keep the ones where the bit is 1, and add them:
| Bit | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Bit × value | 128 | 64 | 0 | 16 | 0 | 4 | 2 | 0 |
128 + 64 + 16 + 4 + 2 = 214. So 11010110₂ = 214₁₀. The small subscript shows the base when it isn't obvious.
Method 2: double and add
This method needs no table. Start with 0, then read the bits from left to right: double the running total and add the current bit.
For 101101:
- 0 × 2 + 1 = 1
- 1 × 2 + 0 = 2
- 2 × 2 + 1 = 5
- 5 × 2 + 1 = 11
- 11 × 2 + 0 = 22
- 22 × 2 + 1 = 45
So 101101₂ = 45. Check it with method 1: 32 + 8 + 4 + 1 = 45.
How to convert decimal to binary
Repeated division by 2
Divide the number by 2, write down the remainder (0 or 1), and repeat with the quotient until it reaches 0. Then read the remainders from the bottom up. Here is 156:
| Division | Quotient | Remainder |
|---|---|---|
| 156 ÷ 2 | 78 | 0 |
| 78 ÷ 2 | 39 | 0 |
| 39 ÷ 2 | 19 | 1 |
| 19 ÷ 2 | 9 | 1 |
| 9 ÷ 2 | 4 | 1 |
| 4 ÷ 2 | 2 | 0 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
Reading upward gives 156 = 10011100₂. Check: 128 + 16 + 8 + 4 = 156. The most common mistake is reading the remainders top-down, which gives the bits in reverse order.
Subtracting powers of 2
For small numbers it is often faster to take the largest power of 2 that fits, subtract it, and repeat. For 100: 64 fits (100 − 64 = 36), then 32 (36 − 32 = 4), then 4 (4 − 4 = 0). Put a 1 under 64, 32 and 4 and a 0 everywhere else: 100 = 1100100₂.
What is hexadecimal?
Hexadecimal (hex) is base 16. It needs 16 digits, so after 0–9 it uses the letters A–F for the values 10 to 15: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Each position is worth 16 times the one to its right: 1, 16, 256, 4,096 and so on.
Programmers use hex because it lines up exactly with binary. Four bits have 16 possible patterns (0000 to 1111), so one hex digit is exactly 4 bits, and two hex digits are exactly one byte. The largest byte, 11111111, is simply FF in hex, while in decimal it is 255, a number that doesn't reveal the bit pattern. That is why memory addresses, color codes, MAC addresses and IPv6 addresses are written in hex.
How to convert hex to decimal
Use the same place-value method with powers of 16, and replace letters with their values:
- 2F = 2 × 16 + 15 × 1 = 32 + 15 = 47
- 1A3 = 1 × 256 + 10 × 16 + 3 × 1 = 256 + 160 + 3 = 419
How to convert decimal to hexadecimal
Decimal to hexadecimal works like decimal to binary, but you divide by 16. Remainders from 10 to 15 become the letters A to F. Here is 1000:
| Division | Quotient | Remainder |
|---|---|---|
| 1000 ÷ 16 | 62 | 8 |
| 62 ÷ 16 | 3 | 14 = E |
| 3 ÷ 16 | 0 | 3 |
Reading the remainders from the bottom up gives 1000 = 3E8₁₆. Check: 3 × 256 + 14 × 16 + 8 = 768 + 224 + 8 = 1000.
Binary to hexadecimal: group the bits in fours
Because one hex digit is four bits, converting binary to hexadecimal needs no arithmetic at all. Split the binary number into groups of four bits (called nibbles), starting from the right, and replace each group using this table:
| Binary | Hex | Decimal | Binary | Hex | Decimal |
|---|---|---|---|---|---|
| 0000 | 0 | 0 | 1000 | 8 | 8 |
| 0001 | 1 | 1 | 1001 | 9 | 9 |
| 0010 | 2 | 2 | 1010 | A | 10 |
| 0011 | 3 | 3 | 1011 | B | 11 |
| 0100 | 4 | 4 | 1100 | C | 12 |
| 0101 | 5 | 5 | 1101 | D | 13 |
| 0110 | 6 | 6 | 1110 | E | 14 |
| 0111 | 7 | 7 | 1111 | F | 15 |
Examples:
- 11010110 → 1101 0110 → D6 (and D6 = 13 × 16 + 6 = 214, the same number as above)
- 101101 → pad on the left to 0010 1101 → 2D (= 45)
Hex to binary works in reverse: replace each hex digit with its four bits. 3E8 → 0011 1110 1000 → 1111101000 once you drop the leading zeros.
Octal in brief
Octal is base 8 and uses the digits 0–7. It works like hex but with three-bit groups, because 2³ = 8. Its best-known use today is Unix file permissions. In chmod 755, each digit is three permission bits (read, write, execute):
- 7 = 111 = rwx
- 5 = 101 = r-x
- 5 = 101 = r-x
So 755 in octal is the bit pattern 111 101 101, which is 493 in decimal. The Chmod Calculator turns ticked permission boxes into the octal number, or shows which permissions a number such as 755 sets.
Where you meet these conversions
- IPv4 addresses. Each of the four numbers is one byte. 192.168.1.10 is 11000000.10101000.00000001.00001010 in binary; 192 = 128 + 64.
- Web colors. A hex color such as #FF8800 is three bytes: red FF = 255, green 88 = 8 × 16 + 8 = 136, blue 00 = 0, so it equals rgb(255, 136, 0). The Color Converter does this for any color.
- Text. In ASCII and Unicode, the capital letter A has the code 65, which is 0x41 in hex and 01000001 in binary. Lowercase a is 97 (0x61, 01100001); the two differ by 32, a single bit.
Prefixes: 0b, 0x and 0o
In code, a prefix tells the compiler which base a number literal uses:
| Prefix | Base | Example | Decimal value |
|---|---|---|---|
0b |
Binary (2) | 0b1011 |
11 |
0o |
Octal (8) | 0o755 |
493 |
0x |
Hexadecimal (16) | 0x3E8 |
1000 |
0x works in almost every language. 0b is supported in Python, JavaScript, Java, C# and C++. 0o is used by Python and JavaScript, while C and C++ write octal with a plain leading zero, so 0755 in C is 493, not 755.
Most languages can also convert strings for you:
# Python
int("1011", 2) # 11
bin(156) # '0b10011100'
hex(1000) # '0x3e8'
int("3E8", 16) # 1000
// JavaScript
parseInt("1011", 2) // 11
(1000).toString(16) // "3e8"
Number("0b1011") // 11
One trap: in JavaScript, parseInt("0b1011") returns 0, because parseInt stops at the first character it can't read and doesn't understand the 0b prefix. Strip the prefix and pass the radix instead, as explained in the MDN reference for parseInt.
A note on negative numbers
Computers usually store negative integers in two's complement. To write −5 in 8 bits, start from 5 = 00000101, flip every bit to get 11111010, then add 1: 11111011. Read as an unsigned number, the same pattern is 251 (256 − 5), or FB in hex. That is why the same byte can mean −5 or 251 depending on whether the program treats it as signed.
Binary, decimal, octal and hex conversion table
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 3 | 11 | 3 | 3 |
| 4 | 100 | 4 | 4 |
| 5 | 101 | 5 | 5 |
| 6 | 110 | 6 | 6 |
| 7 | 111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
| 32 | 100000 | 40 | 20 |
| 64 | 1000000 | 100 | 40 |
| 100 | 1100100 | 144 | 64 |
| 127 | 1111111 | 177 | 7F |
| 128 | 10000000 | 200 | 80 |
| 255 | 11111111 | 377 | FF |
| 256 | 100000000 | 400 | 100 |
Convert any base with the Binary Converter
The free Binary Converter runs in your browser. Type a number and set its base, and it shows the value in binary, octal, decimal and hexadecimal at once, plus one custom output base.
- Any base from 2 to 64, both for the input and for the custom output.
- Prefixes and uppercase: it accepts
0b,0oand0xwhen they match the input base, and uppercase letters such asFFup to base 36. Above base 36, lowercase and uppercase letters are different digits. - Clear errors: an invalid digit, such as a 2 in binary, shows which digits the base allows, and a
0xprefix with base 10 tells you to switch the base to 16. - Bit length: it shows how many bits the number needs, for example 6 for 42 (101010).
- Large numbers: it converts very long integers exactly, such as a full 128-bit IPv6 address written as one number.
A few limits to know: it converts non-negative whole numbers only, so a minus sign or a decimal point is rejected; hex output is lowercase and without leading zeros; and the "Base64 (64)" row is a base-64 number using the digits 0–9, a–z, A–Z, + and /, not Base64 text encoding.
FAQ
What is the largest number you can store in 8 bits?
255, written as 11111111 in binary or FF in hex. Eight bits give 2⁸ = 256 different patterns, which cover 0 to 255. Sixteen bits reach 65,535, and each extra bit doubles the range.
Why do programmers use hexadecimal instead of decimal?
Because each hex digit maps to exactly four bits, you can read the bit pattern straight from the hex digits. A byte is always two hex digits (00 to FF). Decimal has no such fit: 255 and 256 look similar in decimal but are 11111111 and 100000000 in binary.
How do you convert a binary fraction to decimal?
Bits after the binary point are worth 1/2, 1/4, 1/8 and so on. So 101.11₂ = 4 + 1 + 0.5 + 0.25 = 5.75. Many decimal fractions, such as 0.1, have no exact binary form, which is why 0.1 + 0.2 isn't exactly 0.3 in most programming languages. The Binary Converter handles whole numbers only.
Is binary code the same as ASCII?
No. Binary is the number system; ASCII is a table that assigns a number to each character. The letter A is ASCII code 65, and that number is stored as the bits 01000001.
Try it free: Integer Base Converter Free to use, no account needed.