How to Convert Binary to Decimal
Write place values 1, 2, 4, 8, 16… from right to left under the binary digits, then add the values where the digit is 1. Try it live below — type a binary number and the decimal answer appears instantly.
Binary to Decimal Converter
Type in either box. Both stay in sync.
Full converter (all five bases) → · How to convert decimal to binary →
Step by step
- Write place values. Under the binary digits, write 1, 2, 4, 8, 16, 32… from right to left. Each place is double the one before it.
- Keep the 1-bits. Keep the place values where the binary digit is 1. Ignore the 0-bits.
- Add them up. The sum is the decimal number.
- Check. Type the binary number in the converter above and compare.
Worked example: 101010₂ → 42₁₀
| Binary digit | 1 | 0 | 1 | 0 | 1 | 0 |
|---|---|---|---|---|---|---|
| Place value | 32 | 16 | 8 | 4 | 2 | 1 |
| Counted? | Yes | No | Yes | No | Yes | No |
Add the counted values: 32 + 8 + 2 = 42. So 101010₂ in binary is 42₁₀ in decimal.
Second example: 1010 → 8 + 2 = 10. Third: 1111 → 8 + 4 + 2 + 1 = 15.
Binary to decimal table (0–15)
| Binary₂ | Decimal₁₀ | Binary₂ | Decimal₁₀ |
|---|---|---|---|
| 0 | 0 | 1000 | 8 |
| 1 | 1 | 1001 | 9 |
| 10 | 2 | 1010 | 10 |
| 11 | 3 | 1011 | 11 |
| 100 | 4 | 1100 | 12 |
| 101 | 5 | 1101 | 13 |
| 110 | 6 | 1110 | 14 |
| 111 | 7 | 1111 | 15 |
How to convert binary to decimal in code
Python
def binary_to_decimal(bits):
result = 0
for digit in bits:
result = result * 2 + int(digit)
return result
print(binary_to_decimal("101010")) # 42
# Shortcut: int("101010", 2) → 42 Java
// Shortcut
int decimal = Integer.parseInt("101010", 2); // 42
// Manual loop
int binaryToDecimal(String bits) {
int result = 0;
for (int i = 0; i < bits.length(); i++) {
result = result * 2 + (bits.charAt(i) - '0');
}
return result;
} C
#include <stdio.h>
#include <string.h>
int binaryToDecimal(const char *bits) {
int result = 0;
for (size_t i = 0; i < strlen(bits); i++) {
result = result * 2 + (bits[i] - '0');
}
return result;
}
int main(void) {
printf("%d", binaryToDecimal("101010")); // prints 42
return 0;
} These snippets assume the input contains only 0s and 1s. Validate first in real code. RadixFlip also handles a leading minus: -1010 in binary is -10 in decimal.
Frequently asked questions
How do I convert binary to decimal step by step?
Write the place values 1, 2, 4, 8, 16, 32, … from right to left under the binary digits. Add the place values where the digit is 1 and ignore the rest. Example: 101010 → 32 + 8 + 2 = 42.
How do I convert binary to decimal by hand?
Work from right to left. The rightmost bit is worth 1, the next 2, then 4, 8, 16, and so on, doubling each time. Add up the values of the 1-bits. For 101010: 32 + 8 + 2 = 42. Double-check by converting back: 42 ÷ 2 remainders read bottom to top give 101010.
How do I convert binary to decimal in Python?
Use int("101010", 2), which returns 42. To do it by hand, loop over the digits: result = result * 2 + int(digit) for each digit from left to right.
How do I convert binary to decimal in Java?
Use Integer.parseInt("101010", 2), which returns 42. For a manual version, loop over the characters: result = result * 2 + (c - '0') for each character c.
How do I convert binary to decimal in C?
Loop over the string: result = result * 2 + (s[i] - '0') for each character. Validate first that every character is 0 or 1, and handle an optional leading minus.
What is 101010 in decimal?
101010 in binary is 42 in decimal. Check: 32 + 8 + 2 = 42.