fork download
  1. #include <stdio.h>
  2.  
  3. int logb2(int x)
  4. {
  5. int y = 0;
  6.  
  7. if (x == 0) {
  8. fprintf(stderr,"Logic error in logb2.\n");
  9. exit(1);
  10. }
  11.  
  12. while ((x & 1) == 0) {
  13. y++;
  14. x >>= 1;
  15. }
  16. return y;
  17. }
  18. int main()
  19. {
  20. int n[5]={2048,1024, 512, 256, 128};
  21. int i;
  22. for(i=0;i<5;i++)printf("%d ",logb2(n[0])-logb2(n[i]));
  23. printf("\n");
  24. return 0;
  25. }
Success #stdin #stdout 0s 4476KB
stdin
Standard input is empty
stdout
0 1 2 3 4