Number Theory & Bases

Binary to Decimal Converter

To convert binary to decimal, multiply each bit by its power of 2 and add the results: binary 1101 = 8 + 4 + 0 + 1 = 13.

Try

Only 0 and 1. Spaces, underscores and a 0b prefix are ignored; use one point for a fraction.

Read as

Result

1101 in decimal: 13

1101 in decimal

11012=131101_{2} = 13

Hexadecimal
D
Octal
15
BitsThe value needs 4 bits without leading zeros
4 bits typed, 3 ones

1101 in binary is 13 in decimal.

Place values of 1101, from the leftmost bit
BitPower of 2Place valueAddsRunning total
12³888
12²4412
02¹2012
12⁰1113
Step-by-step working (4 steps)
  1. Give each bit its place value

    From the right of the number, the places are worth 1, 2, 4, 8, 16, … (powers of 2). Multiply each bit by its place value.

    11012=1⋅23+1⋅22+0⋅21+1⋅201101_{2} = 1 \cdot 2^{3} + 1 \cdot 2^{2} + 0 \cdot 2^{1} + 1 \cdot 2^{0}
  2. Add the place values where the bit is 1

    8 + 4 + 1 = 13.

  3. Check with the doubling method

    Start at 0 and, for each bit from the left, double the total and add the bit: 0 × 2 + 1 = 1; 1 × 2 + 1 = 3; 3 × 2 + 0 = 6; 6 × 2 + 1 = 13.

  4. Result

    11012=13101101_{2} = 13_{10}

Type any binary number to see the place value of every bit and the running total. The converter also reads signed two’s complement values at 8, 16, 32 or 64 bits and binary fractions such as 101.11.

By Hira Noor, mathematicianLast reviewed Free, no sign-up, runs in your browserReport a problem

How to use this calculator

  1. Type the binary number, for example 1101. Spaces and underscores between groups, such as 1010 0101 or 1010_0101, and a 0b prefix are ignored.
  2. The decimal value appears as you type, with a table of every bit, its power of 2 and the running total.
  3. To read the bits as a negative number, set Read as to signed and pick the bit width: 11111111 is 255 unsigned but −1 as a signed 8-bit number.
  4. For a binary fraction, use one point: 101.11 is 5.75. A minus sign in front, as in −101, gives −5. Four dotted groups of 8 bits, such as 11000000.10101000.00000001.00000001, convert as an IP address (192.168.1.1).
  5. Going the other way? The decimal to binary converter turns decimal into binary with every division step.

Formulas

Binary to decimal formula

(bn−1…b1b0)2=bn−1⋅2n−1+⋯+b1⋅21+b0⋅20(b_{n-1} \ldots b_1 b_0)_2 = b_{n-1} \cdot 2^{n-1} + \cdots + b_1 \cdot 2^1 + b_0 \cdot 2^0

Plain-text formula: (b_(n − 1)…b_1b_0)_2 = b_(n − 1) · 2^(n − 1) + ⋯ + b_1 · 2^1 + b_0 · 2^0

bib_i
the bit in position i, either 0 or 1
nn
the number of bits

Each bit is multiplied by 2 raised to its position, counting the rightmost bit as position 0. Since every bit is 0 or 1, this is the sum of the place values where the bit is 1.

Bits after the point

(0.b−1b−2b−3…)2=b−1⋅2−1+b−2⋅2−2+b−3⋅2−3+⋯(0.b_{-1} b_{-2} b_{-3} \ldots)_2 = b_{-1} \cdot 2^{-1} + b_{-2} \cdot 2^{-2} + b_{-3} \cdot 2^{-3} + \cdots

Plain-text formula: (0.b_(−1)b_(−2)b_(−3)…)_2 = b_(−1) · 2^(−1) + b_(−2) · 2^(−2) + b_(−3) · 2^(−3) + ⋯

Places after the point are worth ½ = 0.5, ¼ = 0.25, ⅛ = 0.125 and so on, halving each step. A binary fraction always has a decimal value that ends.

Two’s complement (signed) value

v={uif the top bit is 0u−2wif the top bit is 1v = \begin{cases} u & \text{if the top bit is } 0 \\ u - 2^{w} & \text{if the top bit is } 1 \end{cases}

Plain-text formula: v = {u, if the top bit is 0; u − 2^w, if the top bit is 1

uu
the unsigned value of the bits
ww
the bit width: 8, 16, 32 or 64

Read the bits as an unsigned number u first. If the leftmost of the w bits is 1, subtract 2^w to get the signed value.

Reading the result

The main result is the decimal value. With Read as set to unsigned, the bits are a plain positive number. The panel also lists the signed value: the same bits read as two’s complement at the chosen width. If the top bit is 0, both readings agree. If it is 1, the signed value is the unsigned value minus 2w2^w, so 1111 1011 is 251 unsigned and 251 − 256 = −5 signed.

With the width set to “As typed”, the bit count is exactly what you entered, leading zeros included: 1011 is −5 as a 4-bit number, but 0000 1011 is +11 as an 8-bit number. Pick 8, 16, 32 or 64 to match a byte, a short, an int or a long in code.

How to convert binary to decimal

Write the place values above the bits, starting with 1 on the right and doubling each step to the left: 1, 2, 4, 8, 16, 32, 64, 128. Then add the place values that sit above a 1 and skip the ones above a 0. This is the positional method, and it works for any length.

For example, 1001 = 8 + 1 = 9, 10 = 2, 10110 = 16 + 4 + 2 = 22 and 1111 = 8 + 4 + 2 + 1 = 15. A quick check: a binary number ending in 0 is always even in decimal, and one ending in 1 is always odd.

Place values for converting 10110110 to decimal
Place value1286432168421
Bit10110110
Adds128032160420

The doubling method (double dabble)

The doubling method avoids writing out the place values, which helps with long numbers or mental arithmetic. Start with 0. For each bit, from left to right, double the running total and add the bit. The last total is the decimal value. Some textbooks call this “double dabble”, though in computing that name also refers to a related binary-to-BCD circuit.

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 is 45, the same answer the place values give (32 + 8 + 4 + 1 = 45).

Powers of 2 table

Every place value in binary is a power of 2. The values below cover common word sizes: a byte is 8 bits, so its top place is 27=1282^7 = 128, and a number made of n ones is always 2n−12^n - 1, such as 11111111 = 255.

Powers of 2 used as binary place values
Bit positionPower of 2Decimal value
02⁰1
12¹2
22²4
32³8
42⁴16
52⁵32
62⁶64
72⁷128
82⁸256
92⁹512
102¹⁰1,024
112¹¹2,048
122¹²4,096
152¹⁵32,768
162¹⁶65,536
312³¹2,147,483,648
322³²4,294,967,296
632⁶³9,223,372,036,854,775,808

Binary to decimal table

The table lists 0 to 31 (every 5-bit number) and the byte values people look up most often. For any other number, type it into the converter above.

Binary numbers and their decimal values
BinaryDecimalBinaryDecimal
001000016
111000117
1021001018
1131001119
10041010020
10151010121
11061011022
11171011123
100081100024
100191100125
1010101101026
1011111101127
1100121110028
1101131110129
1110141111030
1111151111131
100000321111111127
10000006410000000128
110010010011001000200
1111111025411111111255
10000000025611111010001,000

Signed binary: two’s complement

Computers store negative integers in two’s complement. In a w-bit word the top bit carries the place value −2w−1-2^{w-1} instead of +2w−1+2^{w-1}, so the same bits can mean two different numbers. In 8 bits, 1000 0000 is 128 unsigned and −128 signed, and 1111 1111 is 255 unsigned and −1 signed.

To read a signed value by hand, convert the bits as usual, and if the top bit is 1, subtract 2w2^w: 1111 1011 = 251, and 251 − 256 = −5. The same answer comes from inverting the bits and adding 1 (0000 0100 + 1 = 0000 0101 = 5), then putting a minus sign in front. The width matters: 1111 1011 as a 16-bit number is 0000 0000 1111 1011, which is +251.

8-bit patterns read as unsigned and signed
8-bit patternUnsignedSigned (two’s complement)
0000 000000
0000 000111
0111 1111127127
1000 0000128−128
1000 0001129−127
1111 1011251−5
1111 1110254−2
1111 1111255−1

Binary fractions to decimal

Bits after the binary point have place values ½, ¼, ⅛, 116\frac{1}{16} and so on. So 101.11 = 4 + 1 + 0.5 + 0.25 = 5.75, and 0.011 = 0.25 + 0.125 = 0.375. Every binary fraction has a decimal value that ends, because each place value is 1 divided by a power of 2.

The reverse is not true: many short decimals, such as 0.1, repeat forever in binary. That is why 0.1 + 0.2 is not exactly 0.3 in most programming languages. To convert a decimal fraction to binary, use the number base converter.

Binary IP addresses to decimal

An IPv4 address is 32 bits written as four 8-bit groups called octets. To convert it, convert each octet on its own and keep the dots: 11000000 = 128 + 64 = 192, 10101000 = 128 + 32 + 8 = 168, and 00000001 = 1, so 11000000.10101000.00000001.00000001 is 192.168.1.1. Each octet runs from 0 (00000000) to 255 (11111111).

Subnet masks work the same way: 11111111.11111111.11111111.00000000 is 255.255.255.0, a /24 mask, because it starts with 24 ones. Besides 0, the only octet values a mask can contain are 128, 192, 224, 240, 248, 252, 254 and 255, the running totals of 128 + 64 + 32 + … from the left. Paste a dotted binary address into the converter to see every octet worked out.

Binary to decimal in code and spreadsheets

In Python, int("1101", 2) returns 13 and also accepts a 0b prefix; 0b1101 typed directly is 13 too. In JavaScript, parseInt("1101", 2) returns 13; for more than 53 bits use BigInt("0b" + bits) to keep every digit. In C and C++, strtoul("1101", NULL, 2) returns 13.

In Excel and Google Sheets, =BIN2DEC("1101") returns 13. BIN2DEC accepts at most 10 bits and reads a 10-bit input with a leading 1 as negative two’s complement, so =BIN2DEC("1111111111") is −1. Use this converter for longer numbers or a different width.

Common mistakes

Starting the powers at the left. The rightmost bit is 20=12^0 = 1, not the leftmost. Count positions from the right, or the answer comes out far too large.

Starting at 2 instead of 1. The first place value is 20=12^0 = 1. Writing 2, 4, 8, … for the places makes every answer twice too big, and odd numbers become impossible.

Mixing signed and unsigned. 1111 1111 is 255 or −1 depending on whether it is read as signed. Check which reading your course or code uses, and at which bit width.

Ignoring the width for signed numbers. 1011 is −5 as a 4-bit signed number but 11 as an 8-bit one, because the 8-bit pattern is 0000 1011 and its top bit is 0.

Practice questions with answers

Convert each binary number to decimal, then check your answer in the table or by typing it into the converter, which shows the full working.

Binary to decimal practice questions and answers
QuestionBinaryAnswerWorking
111174 + 2 + 1
21010108 + 2
3110012516 + 8 + 1
41001013732 + 4 + 1
5110010010064 + 32 + 4
610000001129128 + 1
70.1010.6250.5 + 0.125
81111 0000 (signed 8-bit)−16240 − 256

Worked example

Convert 101101 from binary to decimal

Write the binary number 101101 in base 10.

  1. Write the place values from the right: 1, 2, 4, 8, 16, 32. The number has six bits, so the leftmost place is 25=322^5 = 32.
  2. Line up the bits: 1 × 32, 0 × 16, 1 × 8, 1 × 4, 0 × 2, 1 × 1.
  3. Add the place values where the bit is 1: 32 + 8 + 4 + 1 = 45.
  4. Check with the doubling method: 1, 2, 5, 11, 22, 45.

Answer: 101101₂ = 45₁₀. In hexadecimal it is 2D, since 0010 = 2 and 1101 = D.

Frequently asked questions

How do you convert binary to decimal?

Multiply each bit by 2 raised to its position, counting from 0 on the right, and add the results. In practice, add the place values 1, 2, 4, 8, 16, … wherever the bit is 1. For example 1101 = 8 + 4 + 1 = 13.

What is 1001 in decimal?

1001 in binary is 9 in decimal: 1 × 8 + 0 × 4 + 0 × 2 + 1 × 1 = 8 + 1 = 9.

What is 10 in binary to decimal?

Binary 10 is 2 in decimal. The left bit is in the 2s place and the right bit is in the 1s place, so 10 = 1 × 2 + 0 × 1 = 2. Likewise binary 100 is 4 and 1000 is 8.

What is 11111111 in decimal?

11111111 is 255 as an unsigned number: 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1, or 2⁸ − 1. Read as a signed 8-bit two’s complement number, the same bits are −1.

How do you convert a binary fraction such as 101.11?

Bits after the point are worth ½, ¼, ⅛ and so on. So 101.11 = 4 + 1 + 0.5 + 0.25 = 5.75. The converter accepts the point and shows each fractional place value.

How do you convert decimal to binary?

Divide by 2 repeatedly and read the remainders from the last to the first. For 13: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1, so 13 = 1101. The decimal to binary converter shows these steps for any number.

How many bits does a decimal number need?

A positive number n needs ⌊log₂ n⌋ + 1 bits. So 255 needs 8 bits and 256 needs 9. With n bits you can write 0 to 2ⁿ − 1 unsigned, or −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1 signed.

Decimal to Binary Converter

Decimal to binary with each division by 2, padding to 8–64 bits, two’s complement and fractions.

Number Theory & Bases

Hex to Decimal Converter

Hex to decimal with place-value steps, plus binary, octal and any base 2 to 36, fractions included.

Number Theory & Bases

Binary Calculator

Binary addition, subtraction and bitwise operations with steps, at 8 to 64 bits, signed or unsigned.

Number Theory & Bases

Mod Calculator

a mod n with steps, negative numbers, power mod and modular inverses.

Number Theory & Bases

Roman Numeral Converter

Numbers and dates to Roman numerals and back, with a chart, symbol breakdowns and strict validation.

Arithmetic & Numbers

Scientific Calculator

Type or tap expressions with exact fractions, memory, variables, constants and complex mode.

Tools

Sources and further reading

  1. The Art of Computer Programming, Volume 2: Seminumerical Algorithms, 3rd edition, §4.1 Positional Number Systems and §4.4 Radix Conversion, Addison-Wesley (Donald E. Knuth, 1997)
  2. Computer Systems: A Programmer’s Perspective, 3rd edition, §2.2 Integer Representations (unsigned and two’s complement encodings), Pearson (Randal E. Bryant and David R. O’Hallaron, 2016)
  3. Python documentation: int() with a base, and binary literals (0b) (opens in a new tab), Python Software Foundation
  4. BIN2DEC function (opens in a new tab), Microsoft Support
  5. parseInt() (opens in a new tab), MDN Web Docs (Mozilla)

Results are calculated in your browser with methods checked by automated tests, and are intended for learning and general use. For engineering, medical, financial, legal or safety-critical decisions, verify important values independently and follow the rounding rules your work requires. How accurate are these results?