Advertisement
NickG

to_hex

Apr 22nd, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. std::string to_hex(const void *data, const unsigned int size) {
  2.     std::stringstream stream;
  3.     stream << std::uppercase << std::hex;
  4.     const unsigned char *bytes = static_cast<const unsigned char *>(data);
  5.     for (unsigned int i = 0; i<size; ++i) {
  6.         stream << std::setfill('0') << std::setw(2) << static_cast<const int>(bytes[i]) << " ";
  7.     }
  8.     return stream.str().substr(0, stream.str().size()-1);
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement