C语言字符数组如何转成16进制
charpKey=“AA1F1905A8F3E4D3C3C536FE615C93BC”charKey[16]={0xAA,0x1F,0x19,0x05,0xA8,0xF3...
char pKey = “AA1F1905A8F3E4D3C3C536FE615C93BC”
char Key[16] = { 0xAA,0x1F,0x19,0x05,0xA8,0xF3,0xE4,0xD3,0xC3,0xC5,0x36,0xFE,0x61,0x5C,0x93,0xBC };
我想有pKey转换为Key,如何做?
字符串AA转换为16进制0xAA
int str2mem(char* pKey, char* pBuffer)
{
int i;
//unsigned int temp=0;
unsigned int temp;
for (i = 0; i<0x10; ++i)
{
sscanf(pKey + 2 * i, "%02X", &temp);
pBuffer[i] = (char)temp;
}
return 0;
}
这个比较好 展开
char Key[16] = { 0xAA,0x1F,0x19,0x05,0xA8,0xF3,0xE4,0xD3,0xC3,0xC5,0x36,0xFE,0x61,0x5C,0x93,0xBC };
我想有pKey转换为Key,如何做?
字符串AA转换为16进制0xAA
int str2mem(char* pKey, char* pBuffer)
{
int i;
//unsigned int temp=0;
unsigned int temp;
for (i = 0; i<0x10; ++i)
{
sscanf(pKey + 2 * i, "%02X", &temp);
pBuffer[i] = (char)temp;
}
return 0;
}
这个比较好 展开
2个回答
展开全部
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int main(void)
{
char *pKey = "AA1F1905A8F3E4D3C3C536FE615C93BC";
int n=strlen(pKey)/2,i;
char *Key=(char *)malloc(sizeof(char)*n);
for(i=0;i<n;++i)
{
sscanf(pKey+2*i,"%2X",Key+i);
}
for(i=0;i<n;++i)
{
printf("%#02hhX ",Key[i]);
}
return 0;
}
追问
Key会写越界
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询