 3

# Binary to Decimal

Difficulty: EASY
Avg. time to solve
15 min
Success Rate
80%

Problem Statement
Suggest Edit

#### Note:

``````A binary string is a string in which all characters are either ‘1’ or ‘0’.
``````

#### Input Format:

``````The first line contains an integer 'T' which denotes the number of test cases or queries to be run.

The first line of each test case contains a single integer ‘N’ denoting the size of the given string.

The second line of each test case contains the string ‘S’  .
``````

#### Output Format:

``````For each test case, print the corresponding Decimal number (as Integer).

The output of each test case will be printed in a separate line.
``````

#### Note:

``````You do not need to input or print anything, as it has already been taken care of. Just implement the given function.
``````

#### Constraints:

``````1 <= T <= 5
1 <= N <= 30

Where ‘T’ is the total number of test cases and ‘N’ is the size of the given string.

The second line of each test case contains the string ‘S’.

Time limit: 1 sec
``````

#### 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.
``````   Console