Guest User

Untitled

a guest
Jan 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1.     public static void printBits(int num){
  2.         String temp = "";
  3.         String temp2 = "";
  4.         int currentBit = 1;
  5.         for(int i = 0; i < 32; i++){
  6.             if((num & currentBit) != 0){
  7.                 if(i > 8){
  8.                     temp = "|" +  1 + " |" + temp;
  9.  
  10.                 }
  11.                 else{
  12.                     temp = "|" +  1 + "|" + temp;
  13.                 }
  14.  
  15.             }
  16.             else{
  17.                 if(i > 8){
  18.                     temp = "|" +  0 + " |" + temp;
  19.  
  20.                 }
  21.                 else{
  22.                     temp = "|" +  0 + "|" + temp;
  23.                 }           }
  24.  
  25.             temp2 = "|" + (i + 1) + "|" + temp2;
  26.             currentBit = currentBit << 1;
  27.         }
  28.         System.out.println(temp);
  29.         System.out.println(temp2);
  30.     }
Add Comment
Please, Sign In to add comment