SHARE
TWEET

printf_bits

Bisus Sep 23rd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void printf_bits(unsigned int x);
  2.  
  3. void printf_bits(unsigned int x)
  4. {
  5.     int len = sizeof(int)*8;// Длина
  6.     int i, j;
  7.  
  8.     for(i = len - 1; i>=0; i--)
  9.     {
  10.         if( x&(1 << i) )
  11.             break;
  12.     }
  13.     // i - номер старшего разряда
  14.  
  15.     for(j = i; j>=0; j--)
  16.         printf("%d", (x >> j)&1 );
  17.  
  18.     printf("\n");
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top