fork(34) download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. unsigned long address = 0;
  8. char c;
  9.  
  10. cout << hex << setfill('0');
  11. while( cin.good() )
  12. {
  13. int nread;
  14. char buf[16];
  15.  
  16. for( nread = 0; nread < 16 && cin.get(buf[nread]); nread++ );
  17. if( nread == 0 ) break;
  18.  
  19. // Show the address
  20. cout << setw(8) << address;
  21.  
  22. // Show the hex codes
  23. for( int i = 0; i < 16; i++ )
  24. {
  25. if( i % 8 == 0 ) cout << ' ';
  26. if( i < nread )
  27. cout << ' ' << setw(2) << (unsigned)buf[i];
  28. else
  29. cout << " ";
  30. }
  31.  
  32. cout << " ";
  33. for( int i = 0; i < nread; i++)
  34. {
  35. if( buf[i] < 32 ) cout << '.';
  36. else cout << buf[i];
  37. }
  38.  
  39. cout << "\n";
  40. address += 16;
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 2900KB
stdin
Hello there, this is a test binary file.
What do you think?

.
stdout
00000000  48 65 6c 6c 6f 20 74 68  65 72 65 2c 20 74 68 69  Hello there, thi
00000010  73 20 69 73 20 61 20 74  65 73 74 20 62 69 6e 61  s is a test bina
00000020  72 79 20 66 69 6c 65 2e  0a 57 68 61 74 20 64 6f  ry file..What do
00000030  20 79 6f 75 20 74 68 69  6e 6b 3f 0a 0a 2e         you think?...