Binary to Decimal


Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

輸入一個二進制數字(只包含 0 和 1),請輸出它所代表的十進制整數。 可用Math.pow(a, b)公式

轉換步驟(以 1101 為例)

位數 2的冪次方
1 ( 2^0 ) = 1
0 ( 2^1 ) = 2
1 ( 2^2 ) = 4
1 ( 2^3 ) = 8

將所有計算結果加總:
( 8 + 4 + 0 + 1 = 13 )

所以 1101(₂) = 13(₁₀)

輸入

一個只包含 0 和 1 的字串。

輸出

輸出該數字的十進制值。

sample input1

1010

sample output1

10

sample input2

1111

sample output2

15

Comments

There are no comments at the moment.