Guest User

Untitled

a guest
Jun 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11. ifstream ifd("C:\Users\", ios::binary | ios::ate);
  12. int size = ifd.tellg();
  13. ifd.seekg(0, ios::beg);
  14. vector<char> buffer;
  15. buffer.resize(size);
  16. ifd.read(buffer.data(), size);
  17.  
  18.  
  19. const int N = 16;
  20. const char hex[] = "0123456789ABCDEF";
  21.  
  22. char buf[N*4+5+2];
  23.  
  24. for (int i = 0; i < buffer.size(); ++i)
  25. {
  26. int n = i % N;
  27. if (n == 0)
  28. {
  29. if (i)
  30. puts(buf);
  31. memset(buf, 0x20, sizeof(buf));
  32. buf[sizeof(buf) - 2] = 'n';
  33. buf[sizeof(buf) - 1] = '';
  34.  
  35. }
  36. unsigned char c = (unsigned char)buffer[i];
  37.  
  38. buf[n*3+0] = hex[c / 16];
  39. buf[n*3+1] = hex[c % 16];
  40.  
  41. buf[3*N+5+n] = (c>=' ' && c<='~') ? c : '.';
  42. }
  43. puts(buf);
  44.  
  45.  
  46. }
Add Comment
Please, Sign In to add comment