怎么將CString類型的變量 s="16ac8e54" 轉(zhuǎn)換成 unsigned char t[100] ={0x16,0xac,0x8e,0x54}最好能給具體代碼
2 回答

慕后森
TA貢獻(xiàn)1802條經(jīng)驗 獲得超5個贊
123456789101112 | #include<stdio.h> #include <afx.h> #define hex2val(a) (('0'<=a&&a<='9')?(a-'0'):(a-'a'+10)) int main() { CString s= "16ac8e54" ; unsigned char t[100]; int k=0; for ( int i=0;i<s.GetLength()-1;i+=2) { t[k++]=hex2val(s[i])*16+hex2val(s[i+1]); } |
12 | for (i=0;i<k;i++) printf ( "0x%x " ,t[i]); |
12 | return 0; } |
- 2 回答
- 0 關(guān)注
- 918 瀏覽
添加回答
舉報
0/150
提交
取消