fork(1) download
  1. #include <stdio.h>
  2.  
  3. /* Number of bits in inttype_MAX, or in any (1<<b)-1 where 0 <= b < 3E+10 */
  4. #define IMAX_BITS(m) ((m) /((m)%0x3fffffffL+1) /0x3fffffffL %0x3fffffffL *30 \
  5.   + (m)%0x3fffffffL /((m)%31+1)/31%31*5 + 4-12/((m)%31+3))
  6. #define UNSIGNED_BIT IMAX_BITS((unsigned)-1)
  7.  
  8. int main(void) {
  9. unsigned x = 4711;
  10.  
  11. unsigned mask = 1U << (UNSIGNED_BIT - 1); // most significant bit
  12. while (mask && !(x&mask)) mask >>= 1; // ignore leading zeros
  13. if (mask) // still bits to process ?
  14. {
  15. for (; mask; mask >>= 1)
  16. {
  17. // output '0' or '1'
  18. // !! normalizes the result of the bitwise and to 0 or 1
  19. putchar('0' + !!(x&mask));
  20. }
  21. }
  22. else putchar('0'); // if only 0 bits found, output 0
  23.  
  24. putchar('\n');
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
1001001100111