Gistrec

HEX dump object

Dec 15th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. /**
  2.  * HEX-dump любого объекта
  3.  * @param obj   - объект, который нужно вывести
  4.  * @param count - количество байт для вывода
  5.  */
  6. template <class Type>
  7. void dump(Type const &obj, int count = sizeof(Type)) {
  8.     for (int i = 0; i < count; i++) {
  9.         if      (i % 8 == 0 && i != 0) std::cout << std::endl;
  10.         else if (i % 4 == 0 && i != 0) std::cout << "    ";
  11.         std::cout << "0x" << std::setfill('0') << std::setw(2) << std::hex << (((char *) &obj)[i] & 0xFF) << " ";
  12.     }
  13.     std::cout << std::endl;
  14. }
Add Comment
Please, Sign In to add comment