Advertisement
rafikamal

Print Binary

Feb 8th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.25 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void printBinary(int n);
  4.  
  5. int main()
  6. {
  7.     int n = 5;
  8.    
  9.     printBinary(n);
  10.    
  11.     return 0;
  12. }
  13.  
  14. void printBinary(int n)
  15. {
  16.     unsigned int i;
  17.     for(i = 1<<31; i >= 1; i >>= 1)
  18.     {
  19.         if(i & n) printf("1");
  20.         else printf("0");
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement