Binary to Decimal Conversion

Convert a given binary number, represented as a string 'S' of size 'N', into its decimal equivalent integer and output it.

Input:

The first line contains an integer 'T', denoting the number of test cases.
The first line of each test case contains a single integer 'N', the length of the binary string.
The second line contains the binary string 'S'.

Output:

Print the decimal equivalent for each test case on a new line.

Example:

Input:
2
3
101
4
1101

Output:
5
13

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 30

Note:

A binary string consists solely of '0' and '1' characters.

AnswerBot
4mo

Convert a binary string to its decimal equivalent integer.

  • Iterate through the binary string from right to left, multiplying each digit by 2 raised to the power of its position.

  • Add the results of the m...read more

Help your peers!
Select
Add answer anonymously...

Blackrock Software Developer interview questions & answers

A Software Developer was asked Q. Validate Binary Search Tree Problem Statement Your task is to determine if a giv...read more
A Software Developer was asked Q. Bridge in Graph Problem Statement Given an undirected graph with V vertices and ...read more
A Software Developer was asked Q. Shortest Distance in a Binary Search Tree Your task is to determine the shortest...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Validate Binary Search Tree Problem Statement Your task is to determine if a giv...read more
A Software Developer was asked Q2. Bridge in Graph Problem Statement Given an undirected graph with V vertices and ...read more
A Software Developer was asked Q3. Shortest Distance in a Binary Search Tree Your task is to determine the shortest...read more
Blackrock Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits