public static void main( String [] args ){ getBinaryNumberFromUser(); //asks the user to type a binary number while( notDone() ){ int binary_digit = getNextDigit(); //moves right to left System.out.println( binary_digit ); } //let's see what 2**3 is in decimal int decimal_number = (int)Math.pow(2, 3); System.out.println("2**3 = " + decimal_number); } //end main Type in a binary number: BinaryToDecimal.java
public static void main( String [] args ){ getBinaryNumberFromUser(); //asks the user to type a binary number while( notDone() ){ int binary_digit = getNextDigit(); //moves right to left System.out.println( binary_digit ); } //let's see what 2**3 is in decimal int decimal_number = (int)Math.pow(2, 3); System.out.println("2**3 = " + decimal_number); } //end main BinaryToDecimal.java
DecimalToBinary.java public static void main( String [] args ){ int n = getBase10IntFromUser(); for(int i = 0; i< n; i++){ if( i%2 == 0) appendNextDigit( 0 ); else appendNextDigit( 1 ); } printNumber(); } //end main Type in a decimal number: 4 Binary Number initempty i=00 i=101 i=2010 i=30101 Binary number = 0101
DecimalToBinary.java public static void main( String [] args ){ int n = getBase10IntFromUser(); for(int i = 0; i< n; i++){ if( i%2 == 0) appendNextDigit( 0 ); else appendNextDigit( 1 ); } printNumber(); } //end main