Java Programs

Write a Java program to convert binary to decimal?


/* Java Program to convert binary to decimal*/
public class BinaryToDecimal {
     public static void main(String a[]){
           int binary = 111; /* give required binary number here */
           int decimal = 0;
           int power = 0;
           while (binary > 0){
                int reminder = binary % 10;
                decimal += reminder * Math.pow(2, power);
                binary = binary / 10;
                power++;
           }
           System.out.println("required Decimal Number : "+decimal);
     }
}
www.000webhost.com