# 2進製到10進制在線轉換工具

2進制2

10進制10

16進制16

8進制8

## 如何進行2進製到10進制轉換?

dn-1dn-2...d2d1d0

Decimal Output = dn-1 × 2n-1 + ... + d1 × 21 + d0 × 20

Decimal Output = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 13

Example 2: 2進制數字"0.101" 轉換為10進制數字:

Decimal Output = 0 × 20 + 1 × 2-1 + 0 × 2-2 + 1 × 2-3 = 0.625

## 2進製到10進制轉換錶:

2進制 10進制 2進制 10進制
1 1 10101 21
10 2 10110 22
11 3 10111 23
100 4 11000 24
101 5 11001 25
110 6 11010 26
111 7 11011 27
1000 8 11100 28
1001 9 11101 29
1010 10 11110 30
1011 11 11111 31
1100 12 100000 32
1101 13 100001 33
1110 14 100010 34
1111 15 100011 35
10000 16 100100 36
10001 17 100101 37
10010 18 100110 38
10011 19 100111 39
10100 20 101000 40

## 用Python進行2進製到10進制轉換:

```def binary_to_decimal(binary_str):
decimal_number = int(binary_str, 2)
return decimal_number

binary_input = '1101'
decimal_output = binary_to_decimal(binary_input)
print('decimal result is:{0}'.format(decimal_output))

-------------------
decimal result is:13```

## 用Java進行2進製到10進制轉換:

```public class NumberConvertManager {
public static int binary_to_decimal(String binary_str) {
return Integer.parseInt(binary_str, 2);
}

public static void main(String[] args) {
String binary_input  = "1101";
int decimal_output = binary_to_decimal(binary_input);
System.out.println("decimal result is:" + decimal_output);
}
}

-------------------
decimal result is:13```