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. int n = 0x41E - (t.asInt[LE] >> 20);
  11. return 32- (n & 31) + (n >> 9);
  12. }
  13. int main(int argc, char **argv) {
  14. int j=2,i=0;
  15. for (;i<25;++i,j<<=1){
  16. unsigned int d = j|1;
  17. printf("%lu==%lu\n", bits0(d), bits1(d));
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
2==2
3==3
4==4
5==5
6==6
7==7
8==8
9==9
10==10
11==11
12==12
13==13
14==14
15==15
16==16
17==17
18==18
19==19
20==20
21==21
22==22
23==23
24==24
25==25
26==26