53. Binary to Decimal

Acceptance — 0 accepted 0 submissions

Easy
LoopsMathStrings
No companies listed
Computers store everything as 0s and 1s. Your friend's electronics project prints numbers in binary, and you need to read them as normal decimal numbers.

Each position is a power of 2 from the right: 1011 = 1×8 + 0×4 + 1×2 + 1×1 = 11.
Given a binary string, print its decimal value.

Input Format
A single line containing a binary string (only 0 and 1).

Output Format
Print the decimal value.

Constraints
• 1 ≤ length ≤ 30
• The string has no leading zeros unless it is exactly 0.

Example 1

Input
1011
Output
11

Explanation 8 + 0 + 2 + 1 = 11.

Example 2

Input
0
Output
0

Explanation Zero is zero in every base.

Example 3

Input
11111111
Output
255

Explanation Eight 1s = 255, the largest value in one byte.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
11
No results yet
Run your code to test it against the sample cases.
Problem List