Conversion of binary number to decimal number using java programming language



import java.io.*;
class Test {


    public static void main(String[] args) throws IOException {


 long  no,n=0l,j=1,rem,no1;
 System.out.println("Enter the binary number");
 BufferedReader br=new BufferedReader(new InputStreamReader (System.in));


 no=Long.parseLong(br.readLine());
 no1=no;
 while(no!=0){
   rem=no%10;
   n=n+rem*j;
   j=j*2;
    no=no/10;
 }


 System.out.println("The value of binary no. "+no1+" is "+n);
  }
}



Conversion of binary number to decimal number using java programming language


No comments: