fork(2) download
  1. #include <stdio.h>
  2.  
  3. unsigned int bits0(unsigned int num) {
  4. int count = 0; while(num) num >>=1, ++count; return count;
  5. }
  6. #define LE 1
  7. unsigned int bits1(unsigned int num) {
  8. union {unsigned int asInt[2];double asDouble;} t;
  9. t.asDouble = (double)num;
  10. return (t.asInt[LE] >> 20)-0x400+2;
  11. }
  12. int main(int argc, char **argv) {
  13. int j=1<<12,i=0;
  14. for (;i<10;++i,j<<=1){
  15. unsigned int d = j|1;
  16. printf("%lu==%lu\n", bits0(d), bits1(d));
  17. }
  18. for (i=1;i<65536;++i)
  19. if(bits0(i)!=bits1(i))
  20. printf("ERROR i=%d %lu!=%lu\n", bits0(i), bits1(i));
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
13==13
14==14
15==15
16==16
17==17
18==18
19==19
20==20
21==21
22==22