Download presentation
Presentation is loading. Please wait.
1
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 1 0 1 1 0 Type in a binary number: 10110 BinaryToDecimal.java
2
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 1 0 1 1 0 BinaryToDecimal.java
3
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
4
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.