# Java binary to decimal

This Tutorial helps you to know the code for Java binary to a decimal number.

Tutorials

# Java binary to decimal

This Tutorial helps you to know the code for Java binary to a decimal number.

In this Tutorial we want to describe you a code that help you in understanding a how to get a 'Java binary to decimal'. For this we have a class BinarytoDecimal, Inside this class we have a main method that includes-

1)Buffered Reader   -  This is used to read a character stream from a file present in input stream reader.

The System.out .print  print  the binary specified  inside the braces.

2)readline ( )   - This is used to read the binary value entered by the user and store the value in a string variable s.

3)Integer.Parse ( )  -The integer class has a method parseInt( ) that returns you the integer value from  string passed as argument representation.

Finally the System.out.println print the decimal value from the binary value.

BinarytoDecimal.java

```import java.io.BufferedReader;
public class BinarytoDecimal {

public static void main(String[] args) throws Exception {
System.out.println("Enter the binary value:");
System.out.println("Decimal value is : "+Integer.parseInt(s, 2));

}
}
```

Output of the program

 ``` Enter the binary value: 110111 Decimal value is : 55```

# Java binary to decimal

Related Tutorials

Discuss: Java binary to decimal

Subject (*):

mhira
January 13, 2012
decimal to binary 210 code

ineed a code
Nawras
March 5, 2012
thank you

I didn't know that parseInt() can do this conversion between number formats, thanks
Edgar
March 18, 2012
BInary to Decimal

import java.util.Scanner; public class BintoDec { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int bin, dec=0, pos=1, f; bin = scan.nextInt(); while(bin>0){ f=bin%10; dec+=pos*f; pos*=2; bin/=10; } System.out.println(dec); } }