Java Program to convert binary number to decimal number


Use the parseInt() method with the second parameter as 2 since it is the radix value. The parseInt() method has the following two forms.

static int parseInt(String s)
static int parseInt(String s, int radix)

To convert binary to decimal, use the 2nd syntax and add radix as 2, since binary radix is 2.

Integer.parseInt("1110", 2)

Example

 Live Demo

public class Demo {
   public static void main( String args[] ) {
      // converting to decimal
      System.out.println(Integer.parseInt("1110", 2));
   }
}

Output

14

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

433 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements