Binary to Decimal Converter
Binary to decimal converter: add the place value of every 1 bit, counting 1, 2, 4, 8 from the right, so 10110101 is 128 + 32 + 16 + 4 + 1 = 181. Spaces, underscores and a 0b prefix are accepted, long values stay exact, and the working is shown in your browser.
| Bit | Position from the right | Place value |
|---|---|---|
| 1 | 7 | 128 |
| 1 | 5 | 32 |
| 1 | 4 | 16 |
| 1 | 2 | 4 |
| 1 | 0 | 1 |
Binary to decimal: add the place values
A binary number is a sum of powers of two. Each position, counted from the right starting at zero, is worth twice as much as the one before it: 1, 2, 4, 8, 16, 32, 64, 128, and so on. A digit of 1 means the position counts, a digit of 0 means it does not, so converting binary to decimal is a matter of adding up the place values under the 1 bits. This is the method that the converter shows for a single value, and it is the only one you have to know.
In the picture the bits 10110101 sit above the weights 128, 64, 32, 16, 8, 4, 2 and 1. The 1 bits are at 128, 32, 16, 4 and 1, which add up to 181. The zero bits, at 64, 8 and 2, are left out. The same sum written as powers of two is 2⁷ + 2⁵ + 2⁴ + 2² + 2⁰ = 128 + 32 + 16 + 4 + 1 = 181. Paste the number into the converter above and the table under the result lists each of those place values, so you can follow the arithmetic.
A worked example, digit by digit
Take 10110101 again and work from the right. The rightmost bit is position 0 and has the value 2⁰ = 1. The next one to the left is position 1, value 2, and so on to the leftmost bit, position 7, value 128. Multiply every bit by its place value and add the products.
| Bit | Position | Place value | Bit × place value |
|---|---|---|---|
| 1 | 7 | 128 | 128 |
| 0 | 6 | 64 | 0 |
| 1 | 5 | 32 | 32 |
| 1 | 4 | 16 | 16 |
| 0 | 3 | 8 | 0 |
| 1 | 2 | 4 | 4 |
| 0 | 1 | 2 | 0 |
| 1 | 0 | 1 | 1 |
The products 128, 0, 32, 16, 0, 4, 0 and 1 add up to 181. Writing every row is slow for a long number, and in practice you only list the 1 bits. A second quick example: 1101 has 1 bits at 8, 4 and 1, which give 13. A third, 100000, has a single 1 at position 5, so it is 32, and every binary number with one 1 followed by zeros is a power of two.
The doubling method, left to right
There is another way that needs no table of powers. Start with 0, and for each bit from the left, double the running total and add the bit. The result after the last bit is the number. For 10110101 the running totals are 1, 2, 5, 11, 22, 45, 90, 181, and the last one, 181, is the answer.
| Next bit | Running total before | Double and add the bit | Running total after |
|---|---|---|---|
| 1 | 0 | 0 × 2 + 1 | 1 |
| 0 | 1 | 1 × 2 + 0 | 2 |
| 1 | 2 | 2 × 2 + 1 | 5 |
| 1 | 5 | 5 × 2 + 1 | 11 |
| 0 | 11 | 11 × 2 + 0 | 22 |
| 1 | 22 | 22 × 2 + 1 | 45 |
| 0 | 45 | 45 × 2 + 0 | 90 |
| 1 | 90 | 90 × 2 + 1 | 181 |
Both methods give the same number because they are the same polynomial written in two orders. The doubling method is the one computers use, and it is how a program reads digits as they arrive. It is also easy to do in your head for bytes: double, double and add, double and add, and so on. It is the better method when the number is written in groups and you want to read it left to right as it comes.
Powers of two worth knowing
If you memorise the first eleven powers of two, you can convert most small binary numbers at a glance. From 2⁰ to 2¹⁰ they are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024. Above that, 2¹⁶ is 65,536 and 2³² is 4,294,967,296, which are the sizes of 16-bit and 32-bit number ranges. A number that is one less than a power of two, such as 7, 15, 31, 63 or 255, is written as all ones in binary, and this gives a fast check: 111111 must be 63.
| Power | Value | All ones in binary | Largest value in that many bits |
|---|---|---|---|
| 2^0 | 1 | — | — |
| 2^1 | 2 | 1 | 1 |
| 2^2 | 4 | 11 | 3 |
| 2^3 | 8 | 111 | 7 |
| 2^4 | 16 | 1111 | 15 |
| 2^5 | 32 | 11111 | 31 |
| 2^6 | 64 | 111111 | 63 |
| 2^7 | 128 | 1111111 | 127 |
| 2^8 | 256 | 11111111 | 255 |
| 2^9 | 512 | 111111111 | 511 |
| 2^10 | 1,024 | 1111111111 | 1,023 |
| 2^12 | 4,096 | 111111111111 | 4,095 |
| 2^16 | 65,536 | 1111111111111111 | 65,535 |
Counting in binary
The table of the first seventeen numbers shows how the bits change. The right-hand bit alternates 0, 1, 0, 1 on every step, the second bit changes every two steps, the third every four, and so on, because each position carries into the next when it reaches its limit, just as 9 becomes 10 in decimal. A number is even exactly when its last bit is 0, and a number is a multiple of four when its last two bits are 00.
| Decimal | Binary | Hex |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 1 | 1 |
| 2 | 10 | 2 |
| 3 | 11 | 3 |
| 4 | 100 | 4 |
| 5 | 101 | 5 |
| 6 | 110 | 6 |
| 7 | 111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
| 16 | 10000 | 10 |
How many bits does a number need?
With n bits you can write 2ⁿ different values, which are the numbers from 0 to 2ⁿ − 1 when the bits are unsigned. To find the number of bits that a decimal number needs, find the smallest power of two above it. 181 is above 128 and below 256, so it needs 8 bits.
| Bits | Different values | Largest unsigned number | Typical use |
|---|---|---|---|
| 4 | 16 | 15 | One hex digit |
| 8 | 256 | 255 | One byte |
| 10 | 1,024 | 1,023 | Analog-to-digital converters |
| 12 | 4,096 | 4,095 | Common sensor readings |
| 16 | 65,536 | 65,535 | Ports, short integers |
| 24 | 16,777,216 | 16,777,215 | RGB color |
| 32 | 4,294,967,296 | 4,294,967,295 | IPv4 address, int |
| 64 | 18,446,744,073,709,551,616 | 18,446,744,073,709,551,615 | Long integers, hashes |
Long binary numbers
Hand conversion works for any length but gets tedious past 16 bits. The converter has no length limit for practical use, and it computes with arbitrary-precision integers, so the result is exact. This matters more than it seems. Many programming languages store numbers as 64-bit floating point, which holds integers exactly only up to 2⁵³, about 9 quadrillion. In JavaScript, parseInt applied to 64 ones returns 18446744073709552000, while the true value is 18,446,744,073,709,551,615. The converter returns the second number.
To convert several values at once, put each on a separate line. Spaces inside a line group the bits of one number, so 1011 0101 is one value, 181, and not two. Leading zeros do not change the result: 00001101 and 1101 are both 13.
Negative numbers and the leading 1
Plain binary has no minus sign, and this converter reads a bit string as an unsigned number, so 11111011 is 251. Computers store negative integers in a convention called two's complement, in which the top bit has a negative weight. Under that convention the same bits mean -5 when the number is 8 bits wide, because 251 − 256 = −5. Which reading is right depends on where the bits came from: a byte of image data or a hash is unsigned, a temperature reading from a sensor is probably signed.
If you know the bits are a signed number of a fixed width, use the two's complement calculator, which reads the bits both ways and shows the steps. A minus sign typed in front of a binary number is also accepted by the converter, and it is kept: −101 is −5. That is a sign and magnitude notation, which is different from the stored form.
Binary fractions
This converter handles whole numbers, but the same idea reaches past the point. Positions to the right of the binary point are worth 1/2, 1/4, 1/8 and so on, each half of the one before. The binary number 101.101 is 4 + 1 + 1/2 + 1/8 = 5.625. Many decimal fractions have no finite binary form: 0.1 in binary repeats forever as 0.000110011…, which is why floating point arithmetic gives 0.1 + 0.2 = 0.30000000000000004. The hex to float converter shows how the bits of a real floating point number are laid out and what value they hold.
| Position | Value | Decimal |
|---|---|---|
| 2^2 | 4 | 4 |
| 2^1 | 2 | 2 |
| 2^0 | 1 | 1 |
| 2^-1 | 1/2 | 0.5 |
| 2^-2 | 1/4 | 0.25 |
| 2^-3 | 1/8 | 0.125 |
| 2^-4 | 1/16 | 0.0625 |
Shortcuts to octal and hex
Binary numbers get long, which is why people regroup them. Three bits make one octal digit and four bits make one hex digit, so you can read a binary number in either base without any arithmetic. 10110101 split into fours is 1011 0101, which is B5 in hex, and B5 is 11 × 16 + 5 = 181. The binary to hex converter does the regrouping, and the hex to binary converter reverses it. When you have a long bit string and need its decimal value, converting to hex first and then to decimal is often easier than adding up 40 place values.
Prefixes, underscores and spaces
Source code writes binary numbers with the prefix 0b, as in 0b10110101, and many languages allow underscores between groups, as in 0b1011_0101. Datasheets and textbooks use spaces or a trailing subscript 2. The converter accepts the 0b prefix, underscores and spaces, ignores leading zeros, and names any other character with its position. A digit other than 0 or 1 is an error, and so is a number with a decimal point, which is outside what this tool converts.
Binary to decimal in code
Every common language converts binary strings. The lines below were run and print 181.
parseInt("10110101", 2); // 181
Number("0b10110101"); // 181
BigInt("0b" + "1".repeat(64)); // 18446744073709551615n, exactecho $((2#10110101))
# 181[Convert]::ToInt64("10110101", 2)
# 181In JavaScript prefer BigInt when the input can be longer than 53 bits. Bash arithmetic is 64-bit and wraps silently above that, and PowerShell's ToInt64 stops at 64 bits with an overflow error. If you need to convert longer numbers in a script, use a big-integer type, or call a tool that does.
Bytes and numbers that span several bytes
A byte holds eight bits and so a value from 0 to 255. Larger numbers are stored in several bytes, and to read them you need to know two things: how many bytes there are and in which order they come. The two orders are called big-endian, with the most significant byte first, and little-endian, with it last. The bytes 01 02 read as 258 in big-endian order (1 × 256 + 2) and as 513 in little-endian order (2 × 256 + 1). Paste a binary number with spaces between the bytes into the converter and it reads them as one value, in the order they are written, which is the big-endian reading.
Because 256 is 2 to the power 8, converting a multi-byte number is the same as converting each byte and weighting it by 256 to the power of its position. A 32-bit number of four bytes b3 b2 b1 b0 is b3 × 16,777,216 + b2 × 65,536 + b1 × 256 + b0. The hex form of the same number is just the four bytes written side by side, which is why people prefer it for long values.
Where binary numbers turn up: addresses and permissions
Some binary numbers you meet outside of programming courses are IPv4 addresses and file permissions. An IPv4 address is 32 bits, written as four bytes in decimal separated by dots. Each byte is converted separately with exactly the method on this page, so 11000000 10101000 00000001 00000001 is 192.168.1.1. A subnet mask is a run of ones followed by zeros, and 11111111 is 255, which is why 255 appears so often in masks.
| Byte (binary) | Decimal |
|---|---|
| 11000000 | 192 |
| 10101000 | 168 |
| 00000001 | 1 |
| 00000001 | 1 |
Unix file permissions use three bits per class of user: read is 4, write is 2 and execute is 1, so the bits 111 give 7, 101 gives 5 and 100 gives 4. The mode 755 is therefore 111 101 101 in binary, which means read, write and execute for the owner and read and execute for the group and everyone else. Colour channels are 8-bit values, and a red of 11111111 is 255, which the RGB to hex converter turns into FF.
Flags and bit masks
Programs often pack several yes-or-no settings into one number, one per bit. A value of 00000101 means that the options worth 4 and 1 are on and the one worth 2 is off, and the decimal number 5 is the sum of those flags. To find out which flags a decimal number contains, you convert it to binary and read the 1 positions, which is the reverse of the method on this page. To test one flag in code, you combine the number with a mask that has only that bit set. Converting a mask to decimal gives the constant you see in source code: the bit mask 00010000 is 16, and 11110000 is 240.
Spreadsheet functions
Spreadsheets have the conversion built in. Excel and Google Sheets both offer BIN2DEC, so =BIN2DEC("10110101") returns 181. The function accepts at most ten binary digits, and it reads a ten-digit number that starts with 1 as a negative number in two's complement, which means that BIN2DEC("1111111111") returns −1 and not 1023. That limit and that sign convention are the reason that a spreadsheet and a general converter can disagree on the same string. Use the converter on this page for values longer than ten bits, and the two's complement calculator when you want the signed reading at a width you choose.
Binary-coded decimal is a different thing
Binary-coded decimal, or BCD, writes each decimal digit as its own group of four bits. The number 12 in BCD is 0001 0010, one group for the 1 and one for the 2. Read as an ordinary binary number the same bits are 10010, which is 18. The two readings differ, and the one that applies depends on the system that produced the bits. BCD is used in some clocks, displays and financial hardware, and its tell-tale sign is that no group goes above 1001. If a number you want to convert has groups of four with values above 9, it is not BCD.
Is it a number or a character?
The bits 01000001 are the number 65, and also the capital letter A when they are read as text. This page treats a binary string as a number and gives 65. If you are decoding a message, with groups of eight that are meant as characters, use the binary to text converter instead. Which reading is right depends on the source. A number written as a long run of bits is a value, and a series of groups of 8 or 7 bits that spells words when you decode it is text.
Practice problems with answers
Try converting these by hand with the place values, then compare with the answers in the table. Eight problems cover the common shapes: a small number, a number with a gap of zeros, a power of two, an all-ones number, a full byte and a long one.
| Binary | Place values added | Decimal |
|---|---|---|
| 1011 | 8 + 2 + 1 | 11 |
| 11001 | 16 + 8 + 1 | 25 |
| 100000 | 32 | 32 |
| 111111 | 32 + 16 + 8 + 4 + 2 + 1 | 63 |
| 100101 | 32 + 4 + 1 | 37 |
| 1100100 | 64 + 32 + 4 | 100 |
| 10101010 | 128 + 32 + 8 + 2 | 170 |
| 1000000000 | 512 | 512 |
Kilobytes, kibibytes and powers of two
Computer memory sizes follow the powers of two, which is why 1024 shows up so often. 2 to the power 10 is 1,024, and a unit of that size is properly called a kibibyte (KiB), while the SI prefix kilo in kilobyte (kB) means exactly 1,000. The next steps are mebibyte (2 to the power 20, 1,048,576 bytes) and gibibyte (2 to the power 30, 1,073,741,824 bytes). Operating systems and manufacturers do not always agree on which one they print, which is why a disk sold as 500 GB can show as a smaller number in a file manager. Writing the sizes in binary makes them easy to recognise: 1 KiB is a 1 followed by ten zeros.
What the converter does and does not do
The converter reads whole, unsigned binary numbers of any length and prints decimal. It does not read fractions, it does not guess a sign, and it does not treat spaces inside a line as separators between numbers. These choices keep the result unambiguous: the same input always gives the same answer, and anything it cannot read is reported with the position of the offending character. Everything is computed in the page. No number you enter is sent to a server, stored or logged, and the tool keeps working if you go offline after the page has loaded.
Mistakes when adding place values
The most frequent error is reading the place values from the left, with the first bit worth 1. The weights always start at 1 on the right-hand side, so the same digits in reverse order give a different number: 1100 is 12, but 0011 is 3. The second is starting at the wrong power, so that the rightmost bit is 2¹ instead of 2⁰ and the result doubles. The third is a slip when adding, which the doubling method avoids because it never has more than one running number to track.
A fourth, quieter mistake is treating a binary string as text. Digits typed in a spreadsheet may be converted to decimal numbers automatically, so 0011 becomes 11 and the leading zeros disappear. Keep binary strings as text in a spreadsheet, or paste them into the converter, which keeps them exactly as typed.
Checking the answer
Three checks take seconds. The parity of the result must match the last bit: an even number ends in 0 and an odd number ends in 1. The result must lie between 2ⁿ⁻¹ and 2ⁿ − 1 when the leading bit is 1 and the length is n: for eight bits starting with 1, the answer is between 128 and 255. And the answer converted back must give the original string, which you can try on the decimal to binary page, where repeated division shows each bit again.
For related tasks the binary to text converter reads the same bits as characters, the hex converter shows a value in several bases at once, and the hex to decimal converter does the same job for base 16.
Questions about binary to decimal
How do you convert binary to decimal?
Write the place values 1, 2, 4, 8, 16 and so on under the bits, starting from the right, and add up the values that sit under a 1. For 1101 the 1 bits are at 8, 4 and 1, so the decimal number is 8 + 4 + 1 = 13. A 0 bit adds nothing.
What is 1010 in decimal?
10. The 1 bits are at the 8 and the 2 positions, and 8 + 2 = 10. In hex the same number is A.
What is the largest number that fits in 8 bits?
255, which is 11111111 in binary. Eight bits give 2 to the power 8, or 256, different patterns, and since the first pattern is 0 the last one is 255. Signed 8-bit numbers run from -128 to 127.
Why does a binary number that starts with 1 not always mean a negative number?
Because a plain binary number has no sign. The leading 1 is only the highest place value. It means negative only when the bits are defined as a signed two's complement number of a fixed width, and then 11111011 is -5 in 8 bits and 251 as an unsigned byte.
Can the converter handle binary numbers with hundreds of digits?
Yes. It uses arbitrary-precision integers, so a binary number of any practical length converts exactly. A language that stores numbers as floating point, JavaScript's parseInt for example, loses the low digits above 53 bits.
