fork(1) download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. using namespace std;
  6.  
  7. // read the number
  8. const int max_size = 64 + 1;
  9. char b[max_size];
  10. cin.getline( b, max_size );
  11.  
  12. // radix 2 string to int64_t
  13. int64_t i = 0;
  14. for ( const char* p = b; *p && *p == '0' || *p == '1'; ++p )
  15. {
  16. i <<= 1;
  17. i += *p - '0';
  18. }
  19.  
  20. //
  21. cout << "decimal: " << i << endl;
  22. cout << hex << "hexa: " << i << endl;
  23. cout << oct << "octa: " << i << endl;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3464KB
stdin
11111111
stdout
decimal: 255
hexa: ff
octa: 377