Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import the scanner object
- public class binaryConversion
- {
- public static void main (String args []){
- /** Create 3 variables, a string for binNum, double for a temp variable to temporarily store a
- * number and a total variable with initialized to 0 to sum the total of each bit's value.
- **/
- // make a new scanner object to allow for user input
- //make the binNum equal to the user input.
- // At the end explain what the line of code below does..
- for (int x=0; x<binNum.length();x++){
- // At the end explain what the line of code below does..
- temp= Integer.parseInt(String.valueOf(binNum.charAt(binNum.length()-1-x)));
- // use the Math.pow method to calculate the value of each bit in the binary number
- //increase the value of the total based on the value of temp.
- }
- System.out.println(total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement