MFC 十六进制CString转为十六进制BYTE数据 如何转换?
CStringreadBuf=“fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
CString readBuf =“ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”
转换为
byte buf[64] ={0xff,0xff.........................0xff}
将 readBuf ="abcdefabcdef"
BYTE *buf= (BYTE*)readBuf.GetBuffer(FileLen);
buf = {ff,ff,a,ff,b,ff,c,ff,d,ff,e,ff,f,ff,a,ff,b,ff,c,ff,d,ff,e,ff,f,ff,ff....}
这些 ff 怎么来的? 展开
转换为
byte buf[64] ={0xff,0xff.........................0xff}
将 readBuf ="abcdefabcdef"
BYTE *buf= (BYTE*)readBuf.GetBuffer(FileLen);
buf = {ff,ff,a,ff,b,ff,c,ff,d,ff,e,ff,f,ff,a,ff,b,ff,c,ff,d,ff,e,ff,f,ff,ff....}
这些 ff 怎么来的? 展开
2个回答
展开全部
memset(buf,0,64)
for(int i=0;i<readBuf.Length();i++)
{
switch(readBuf[i])
{
case 'a':
buf[i+i/2] =buf[i+i/2] I (0x0a<<(i%2)*4);
break;
case 'b':
buf[i+i/2] =buf[i+i/2] I (0x0b<<(i%2)*4);
break;
..........
}
}
如果CString =“abcd”
那么转换后 buf ={0xba,0xdc};
可能你想要的是0xab,0xcd,只需(0x0a<<((i+1)%2)*4);
for(int i=0;i<readBuf.Length();i++)
{
switch(readBuf[i])
{
case 'a':
buf[i+i/2] =buf[i+i/2] I (0x0a<<(i%2)*4);
break;
case 'b':
buf[i+i/2] =buf[i+i/2] I (0x0b<<(i%2)*4);
break;
..........
}
}
如果CString =“abcd”
那么转换后 buf ={0xba,0xdc};
可能你想要的是0xab,0xcd,只需(0x0a<<((i+1)%2)*4);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询