Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void printBits(int num){
- String temp = "";
- String temp2 = "";
- int currentBit = 1;
- for(int i = 0; i < 32; i++){
- if((num & currentBit) != 0){
- if(i > 8){
- temp = "|" + 1 + " |" + temp;
- }
- else{
- temp = "|" + 1 + "|" + temp;
- }
- }
- else{
- if(i > 8){
- temp = "|" + 0 + " |" + temp;
- }
- else{
- temp = "|" + 0 + "|" + temp;
- } }
- temp2 = "|" + (i + 1) + "|" + temp2;
- currentBit = currentBit << 1;
- }
- System.out.println(temp);
- System.out.println(temp2);
- }
Add Comment
Please, Sign In to add comment