fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <bitset>
  4. #include <climits>
  5. #include <type_traits>
  6.  
  7. template <typename T>
  8. constexpr std::size_t bitsInType = sizeof(T) * CHAR_BIT;
  9.  
  10. template <typename T>
  11. std::string binaryReprestation(T value) {
  12. static_assert(std::is_integral<T>::value, "Value needs to be integral");
  13.  
  14. return std::bitset<bitsInType<T>>(value).to_string();
  15. }
  16.  
  17. int main() {
  18. const int value = 1234;
  19.  
  20. std::cout << binaryReprestation(value);
  21. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
00000000000000000000010011010010