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