fork download
  1. #include <iostream>
  2.  
  3. unsigned int power_of_2(unsigned int x) {
  4. for(size_t p2 = 0; p2 < sizeof(x)*8; ++p2) {
  5. if(x & (1 << p2)) {
  6. return p2;
  7. }
  8. }
  9. return 0;
  10. }
  11.  
  12. int main() {
  13. std::cout << power_of_2(0x0080) << " "
  14. << power_of_2(0x0040) << " "
  15. << power_of_2(0x0020) << " "
  16. << power_of_2(0x0010) << " "
  17. << std::endl;
  18. return 0;
  19. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
7 6 5 4