Advertisement
mrScarlett

BinaryConverter

Sep 10th, 2017
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. // import the scanner object
  2. public class binaryConversion
  3. {
  4.     public static void main (String args []){
  5.         /** Create 3 variables, a string for binNum, double for a temp variable to temporarily store a
  6.             * number and a total variable with initialized to 0 to sum the total of each bit's value.
  7.         **/
  8.  
  9.         // make a new scanner object to allow for user input
  10.         //make the binNum equal to the user input.
  11.         // At the end explain what the line of code below does..
  12.         for (int x=0; x<binNum.length();x++){
  13.             // At the end explain what the line of code below does..
  14.             temp= Integer.parseInt(String.valueOf(binNum.charAt(binNum.length()-1-x)));
  15.             // use the Math.pow method to calculate the value of each bit in the binary number
  16.             //increase the value of the total based on the value of temp.
  17.     }
  18.     System.out.println(total);
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement