本文共 998 字,大约阅读时间需要 3 分钟。
#include#include #include typedef unsigned char BOOL_T; typedef unsigned char U8_T; typedef signed char S8_T; typedef unsigned short U16_T; typedef signed short S16_T; typedef unsigned int U32_T; typedef signed int S32_T;typedef unsigned __int64 U64_T;typedef signed __int64 S64_T; typedef float F32_T; typedef double F64_T; typedef char * STR_T;//16进制字符串转为16进制void StrToHex(U8_T* pbDest, U8_T* pbSrc, U8_T nLen){ U8_T h1,h2; U8_T s1,s2; U8_T i; for (i = 0; i < nLen; i++) { h1 = pbSrc[2*i]; h2 = pbSrc[2*i+1]; s1 = toupper(h1) - 0x30; if (s1 > 9) s1 -= 7; s2 = toupper(h2) - 0x30; if (s2 > 9) s2 -= 7; pbDest[i] = s1*16 + s2; }}int main(){ int i; U8_T tmp[12] = "010203040506"; U8_T out[6] = {0}; memset(out, 0 ,8); //16进制字符串转为16进制 StrToHex(out, tmp, 6); for(i = 0; i < sizeof(out); i++) { printf("out[%d] : %x \n", i, out[i]); } return 0; }
运行结果:
转载地址:http://dopcz.baihongyu.com/