怎么将CString类型的变量 s="16ac8e54" 转换成 unsigned char t[100] ={0x16,0xac,0x8e,0x54}最好能给具体代码
2 回答
慕后森
TA贡献1802条经验 获得超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 关注
- 935 浏览
添加回答
举报
0/150
提交
取消
