std::string CSession::MemToHex(const void* src, size_t size, bool upper/* = true*/,char tag/* = 0*/)
{
std::string strDest;
strDest.reserve(2*size);
unsigned char* pSrc = (unsigned char*)src;
unsigned char buf[2];
for (size_t i = 0; i < size; ++i)
{
unsigned char c0 = *pSrc >> 4;
if ( c0 >= 0x0 && c0 <= 0x9)
buf[0] = c0 - 0 + '0';
else
buf[0] = c0 - 10 + (upper ? 'A' : 'a');
unsigned char c1 = *pSrc++ & 0x0F;
if ( c1 >= 0x0 && c1 <= 0x9)
buf[1] = c1 - 0 + '0';
else
buf[1] = c1 - 10 + (upper ? 'A' : 'a');
strDest += (char)buf[0];
strDest += (char)buf[1];
if (tag != 0) strDest += tag;
}
return strDest;
}