Java program to convert binary number to decimal value

The java.lang.Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.

The parseInt(String str, radix r) method of the Integer class parses the given string argument as a signed integer in the radix specified by the second argument and returns it.


import java.util.Scanner;
public class BinaryToDecimal {
   public static void main(String args[]){
      Scanner sc = new Scanner(;
      System.out.println("Enter a binary number ::");
      String binary =;
      int decimal = Integer.parseInt(binary, 2);
      System.out.println("Decimal value of the given binary number is ::"+decimal);


Enter a binary number ::
Decimal value of the given binary number is ::41
Samual Sam
Samual Sam

Learning faster. Every day.