0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

C語(yǔ)言常用的轉(zhuǎn)換工具函數(shù)有哪些

Wildesbeast ? 來(lái)源:21IC ? 作者:21IC ? 2020-10-25 11:31 ? 次閱讀

1、字符串轉(zhuǎn)十六進(jìn)制

代碼實(shí)現(xiàn):

void StrToHex(char *pbDest, char *pbSrc, int nLen){ char h1,h2; char s1,s2; int i; for (i=0; i { h1 = pbSrc[2*i]; h2 = pbSrc[2*i+1]; s1 = toupper(h1) - 0x30; //toupper 轉(zhuǎn)換為大寫字母 if (s1 》 9) s1 -= 7; s2 = toupper(h2) - 0x30; if (s2 》 9) s2 -= 7; pbDest[i] = s1*16 + s2; }}

2、十六進(jìn)制轉(zhuǎn)字符串

代碼實(shí)現(xiàn):

void HexToStr(char *pszDest, char *pbSrc, int nLen){ char ddl, ddh; for (int i = 0; i 《 nLen; i++) { ddh = 48 + pbSrc[i] / 16; ddl = 48 + pbSrc[i] % 16; if (ddh 》 57) ddh = ddh + 7; if (ddl 》 57) ddl = ddl + 7; pszDest[i * 2] = ddh; pszDest[i * 2 + 1] = ddl; } pszDest[nLen * 2] = ‘