add Hex2String function.

This commit is contained in:
hyzboy 2020-11-05 14:00:50 +08:00
parent 94fc90f74d
commit ad4b2cd48c

View File

@ -2830,6 +2830,32 @@ namespace hgl
ParseHexStr((uint8 *)&hc,str,sizeof(HC));
}
template<typename T,typename U>
void Hex2String(T *str,U value,bool upper=true)
{
const uchar A=upper?'A':'a';
const uint size=sizeof(U)*2;
const uint8 *sp=(uint8 *)&value;
T *tp=str;
uint l,r;
for(uint i=0;i<sizeof(U);i++)
{
l=((*sp)&0xF0)>>4;
r= (*sp)&0x0F;
++sp;
if(l<10)*tp++=l+'0';
else *tp++=l-10+A;
if(r<10)*tp++=r+'0';
else *tp++=r-10+A;
}
*tp=0;
}
/**
* 16
* @param str 16