How to Convert Binary Number to Decimal in Java


The example aims to demonstrate how to convert a binary integer number to  a decimal integer one in Java.

Source Code

package com.beginner.examples;

public class ConvertBinaryToInteger {

	public static void main(String[] args) {

		String strBinary = "1010011011";

		// parseInt () method in the Integer class is used to parse a binary
		// number
		//The second parameter represents that the parsed number is binary
		Integer integer = Integer.parseInt(strBinary, 2);

		System.out.println(strBinary+"--->"+integer);

	}

}

Output:

1010011011--->667
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments