fork download
  1.  
  2. #include <iostream>
  3. #include <bitset>
  4. #include <cstdint>
  5.  
  6. int main() {
  7. char c = -127;
  8. int a = static_cast<int>(c);
  9. std::int32_t d = static_cast<int32_t>(c);
  10.  
  11. std::cout << "c = " << c << " As binary: " << std::bitset<8>(c) << std::endl;
  12. std::cout << "a = " << a << " As binary: "<< std::bitset<64>(a) << std::endl;
  13. std::cout << "d = " << d << " As binary: "<< std::bitset<32>(d) << std::endl;
  14. }
Success #stdin #stdout 0s 4456KB
stdin
Standard input is empty
stdout
c = � As binary: 10000001
a = -127 As binary: 1111111111111111111111111111111111111111111111111111111110000001
d = -127 As binary: 11111111111111111111111110000001