//----------------------------------------------------------------------------- // // %%HeaderFileHeader%% // //----------------------------------------------------------------------------- #pragma once //----------------------------------------------------------------------------- #include #include #include //----------------------------------------------------------------------------- // // Display unsigned char as string of hex numbers. // Usage: // std::cout << hex(16); // std::cout << hex(0x10); // std::cout << hex({42, 43, 44}); // struct HexCharStruct { unsigned char c; HexCharStruct(unsigned char _c) : c(_c) { } }; inline std::ostream& operator<<(std::ostream& o, const HexCharStruct& _hs) { return (o << "0x" << std::setfill ('0') << std::setw(2) << std::hex << (int)_hs.c); } inline std::ostream& operator<<(std::ostream& o, const std::vector _vhs) { for (auto&& hs : _vhs) { o << hs; if (&hs != &_vhs.back()) o << " "; } return o; } inline HexCharStruct hex(unsigned char _c) { return HexCharStruct(_c); } inline std::vector hex(const std::vector _vc) { std::vector vec; for (auto c : _vc) { vec.push_back(c); } return vec; }