Java examples for Algorithm:Number
Binary To Decimal with while loop
public class Main { public static void main(String args[]) throws Exception { int mBinary = 111; int dec = 0;/*from w ww . ja va 2 s. c o m*/ int power = 0; while (mBinary > 0) { int temp = mBinary % 10; dec += temp * Math.pow(2, power); mBinary = mBinary / 10; power++; } System.out.print("Decimal : " + dec); } }