如何从二进制转换为十进制?
二进制数是计算机机器可以理解的数字。它是 0 和 1 的组合。由于计算机和少数电子设备仅理解二进制语言,因此它们仅以二进制格式接受输入并以二进制格式返回结果。
在本文中,我们将学习如何将二进制数转换为十进制数。
二进制转十进制公式
要将二进制数转换为十进制数,我们需要对二进制数的每个数字从 0 开始以 2 的幂从右到左执行乘法运算,然后将每个结果相加得到它的十进制数。
使用以下示例可以更好地解释这一点:
示例 1:让我们考虑一个二进制数 1111。我们需要将此二进制数转换为十进制数。
解决方案:
As mentioned in the above paragraph while converting from binary to decimal we need to consider each digit in binary number from right to left.
By this way, we can do binary to decimal conversion.
Note: We represent any binary number with this format (xxxx)2 and decimal in (xxxx)10 format.
示例 2:转换 (101010) 2 ->(?) 10
解决方案:
We keep on increasing the power of 2 as long as number of digits in binary number increases.
示例 3:转换 (11100) 2 ->(?) 10
解决方案:
Resultant Decimal number = 0+0+4+8+16 = 28
So (11100)2->(28)10
There is also another method called Doubling that can be used to convert binary numbers to decimals.
倍增法
为了解释这种方法,我们将考虑一个示例并尝试逐步解决该问题。
示例 1:将二进制数 (10001) 2转换为十进制。
解决方案:
Similar to the above approach, In this approach also consider each digit but from left to right and performs step-wise computations on it.1 0 0 0 1
Step-1 First we need to multiply 0 with 2 and add the 1st digit in binary number.
0 x 2 + 1 = 0 + 1 = 1
Step-2 Now use the result of above step and multiply with 2 and add the second digit of binary number. 1 0 0 0 1
1 x 2 + 0 = 2 + 0 = 2
The same step 2 is repeated until there will be no digit left. The final result will be the resultant decimal number. 1 0 0 0 1
2 x 2 + 0 = 4 + 0 = 4 1 0 0 0 1
4 x 2 + 0 = 8 + 0 = 8 1 0 0 0 1
8 x 2 + 1 = 16 + 1 = 17
So we performed step 2 on all remaining numbers and finally, we left with result 17 which is a decimal number for the given binary number.
So (10001)2->(17)10
示例 2:使用加倍方法将 (111) 2转换为十进制。
解决方案:
1 1 1
0 x 2 + 1 = 0 + 1 = 1 1 1 1
1 x 2 + 1 = 2 + 1 = 3 1 1 1
3 x 2 + 1 = 6 + 1 = 7
The final result is 7 which is a Decimal number for 111 binary number. So (111)2->(7)10
These are the 2 approaches that can be used or applied to convert binary to decimal.