viewing paste Binary Displayer | C++

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
 
const int UNSIGNED_INT_SIZE = 32;
 
void printBinary(unsigned int n){
        
    for(int i = UNSIGNED_INT_SIZE-1; i >= 0; i--)
    {
        std::cout << ((n >> i)&1);
        
        if(i%4 == 0)
            std::cout << " ";
    }
    
}
 
int main () {
    
    unsigned int num;
    
    std::cout << "Input a number greater than 0: ";
    
    std::cin >> num;    
    
    printBinary(num);
    
    return 0;
}
 
Viewed 1547 times, submitted by Streusel.