#pragma once
#include <iostream>
#include <iomanip> //std::hex, std::setw, std::setfill
template <class T>T hex2int(string hexstr);
template <class T>string int2hex(T val, int size);
template <class T>
T hex2int(string hexstr) {
istringstream intstream(hexstr);
T val;
intstream >> hex >> val;
return val;
}
template <class T>
string int2hex(T val, int size) {
ostringstream hexstream;
hexstream << hex << setw(size) << setfill('0') << setiosflags(ios::uppercase) << val;
return hexstream.str();
}
|