字符串字节数组 [英] string to byte array
本文介绍了字符串字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何输入 DEADBEEF
输出 DE
AD
为
EF
四个字节数组?
解决方案
无效hexconvert(字符*文本,无符号的字符字节[])
{
INT I;
INT温度; 对于(I = 0; I&4; ++ⅰ){
sscanf的(文本+ 2 *我,%2X,&安培;温度);
字节[I] =温度;
}
}
How do I input DEADBEEF
and output DE
AD
BE
EF
as four byte arrays?
解决方案
void hexconvert( char *text, unsigned char bytes[] )
{
int i;
int temp;
for( i = 0; i < 4; ++i ) {
sscanf( text + 2 * i, "%2x", &temp );
bytes[i] = temp;
}
}
这篇关于字符串字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文