From ad4b2cd48c9744c3a5e2fed29a15a79d7a5d35b3 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 5 Nov 2020 14:00:50 +0800 Subject: [PATCH] add Hex2String function. --- inc/hgl/type/StrChar.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/inc/hgl/type/StrChar.h b/inc/hgl/type/StrChar.h index 561d64b..67be07e 100644 --- a/inc/hgl/type/StrChar.h +++ b/inc/hgl/type/StrChar.h @@ -2830,6 +2830,32 @@ namespace hgl ParseHexStr((uint8 *)&hc,str,sizeof(HC)); } + template + 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>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进制数值字符串存入处