fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. uint32_t log2(uint32_t n)
  5. {
  6. float f = n;
  7. return (*reinterpret_cast<uint32_t *>(&f) >> 23) - 127;
  8. }
  9.  
  10. int main()
  11. {
  12. uint32_t n;
  13. while(scanf("%u", &n) == 1)
  14. {
  15. printf("%u\n", log2(n));
  16. };
  17. return 0;
  18. }
Success #stdin #stdout 0s 2900KB
stdin
1
2
3
4
8
32
4294967296
stdout
0
1
1
2
3
5
32