In  this tutorial, we will see “How to convert Binary to Decimal number using Java?”

How to convert Binary to decimal number in java

Java – How to convert Binary to Decimal Number? Share on X

/**
 * Using Java, Convert Binary to Decimal Number
 * @author Deepak Verma
 *
 */

import java.util.Scanner;

public class Convert_Binary_To_Decimal_Java_Example {

	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in)) {
			
			System.out.print("Enter a Binary number: ");
			
			String binaryValue = sc.nextLine();
			
			int decimalNumber = Integer.parseInt(binaryValue, 2);
			
			System.out.println("Decimal counterpart: " + decimalNumber);
		
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
	}
}

 

Output:

Enter a Binary number: 00000000000000000000000001100100
Decimal counterpart: 100

How to convert Binary to decimal number in java

Java – How to convert Binary to Decimal Number? Share on X

Do you like this Post? – then check my other helpful posts:

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester.

    He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    View all posts