Update appNew update is available. Click here to update.

Binary to Decimal

Contributed by
Yash_5830
Last Updated: 23 Feb, 2023
Easy
yellow-spark
0/40
Avg time to solve 15 mins
Success Rate 80 %
Share
16 upvotes

Problem Statement

Ninja is given a binary number as a string ‘S’ of size ‘N’, he is asked to convert it into its decimal equivalent (as an Integer) and print it.

Note:

A binary string is a string in which all characters are either ‘1’ or ‘0’.
Detailed explanation ( Input/output format, Notes, Images )

Sample Input 1:

2
7
1010101
4
1011

Sample Output 1:

85
11

Explanation of Sample Input 1:

Test case 1:

The Decimal equivalent of the Binary number “1010101” is 85.

Test case 2:
The Decimal equivalent of the Binary number “1011” is 11.

Sample Input 2:

2
4
1111       
1
0

Sample Output 2:

15
0

Explanation of Sample Input 2:

Test case 1:

The Decimal equivalent of the Binary number “1111” is 15.

Test case 2:

The Decimal equivalent of the Binary number “0” is 0.
Reset Code
Full screen
Auto
copy-code
Console