fork(8) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int bits_needed(uint32_t value)
  5. {
  6. int bits = 0;
  7. if (value >= 0x10000)
  8. {
  9. bits += 16;
  10. value >>= 16;
  11. }
  12. if (value >= 0x100)
  13. {
  14. bits += 8;
  15. value >>= 8;
  16. }
  17. if (value >= 0x10)
  18. {
  19. bits += 4;
  20. value >>= 4;
  21. }
  22. if (value >= 0x4)
  23. {
  24. bits += 2;
  25. value >>= 2;
  26. }
  27. return bits + value;
  28. }
  29.  
  30. int main() {
  31. cout << bits_needed(30665) << endl;
  32. return 0;
  33. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
15