gpt4 book ai didi

c - 我想在 IAR 工作台编译器中将数据从 long 转换为 ASCII

转载 作者:太空宇宙 更新时间:2023-11-03 23:26:43 25 4
gpt4 key购买 nike

我试图在 iar 中将数据从 long 转换为 ASCII,但我没有得到结果

我的预期输出长值为 459150 我在反转字节后得到十六进制值 我在转换为 ASCII 后得到的输出为 0007018E 我得到错误的输出

我在这里尝试了所有转换。

long convertToLong(char* data,const int len)
{
UINT8 hex[8]={0};
bool ret = ConvertToBCD((unsigned char*)data,len,hex);
sendtoUSB("con to BCD",10);
sendtoUSB(hex,len*2);
return hextol(hex,len*2);
}

long hextol(char hexvalue[],int len)
{
long result=0;
int i=0;
while (i<len)
{
result = result * 16;
if(hexvalue[i] >= '0' && hexvalue[i] <= '9')
{
result = result + (hexvalue[i] - '0');
}
else if(hexvalue[i]>= 'a'&& hexvalue[i]<='f')
{
result= result+ (hexvalue[i]- 'a'+10);
}
else if(hexvalue[i]>= 'A'&& hexvalue[i]<='F')
{
result= result+ (hexvalue[i]- 'A'+10);
}
else
{
result=0;
return result;
}
++i;
}
return result;
}

void ltoa(long value,char buf[])
{
int i=0,j=1;
int temp=0;
while(value !=0)
{
temp=value%10;
buf[i++]=temp+0x30;
value /=10;
}
reverse_byte(buf,4);
}

最佳答案

试试这个-

long int var = 0x0007018E;
char buf[100];

snprintf(buf,100,"%ld",var); //what variable having your hex value,pass it instead of var

printf("%s \n",buf);

关于c - 我想在 IAR 工作台编译器中将数据从 long 转换为 ASCII,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25402469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com