7 Dec 2017

write a program in java to convert a Binary number to its equivalent Decimal number



class BinaryToDecimal
{
          public static void main(String[] args)
          {
                   int num=1101,power=0,decimal=0;
                   while(num!=0)
                   {
                                      decimal+=(num%10)*Math.pow(2,power++);
                                      num/=10;
                   }
                   System.out.println(decimal);
          }
}



Output: