fork download
  1. #include <array>
  2. #include <iostream>
  3.  
  4.  
  5. std::string to_hex(unsigned number)
  6. {
  7. static const std::array<char, 16> hexdigits =
  8. {'0', '1', '2', '3', '4', '5', '6', '7',
  9. '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',};
  10. std::string hex;
  11. while (number != 0) {
  12. hex.push_back(hexdigits[number % 16]);
  13. number /= 16;
  14. }
  15. return {hex.rbegin(), hex.rend()};
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21. unsigned number;
  22. std::cin >> number;
  23. std::cout << to_hex(number) << std::endl;
  24. }
  25.  
Success #stdin #stdout 0s 3476KB
stdin
3586
stdout
E02