这是我的逻辑,在 C 中将 HEX 转换为 ASCII 转换:
for (i=0;i<ArraySize;i++)
{
/*uses a bitwise AND to take the top 4 bits from the byte,
0xF0 is 11110000 in binary*/
char1 = Tmp[i] & 0xf0;
char1 = char1 >> 4;
/*bit-shift the result to the right by four bits (i.e. quickly divides by 16)*/
if (char1 >9)
{
char1 = char1 - 0xa;
char1 = char1 + 'A';
}
else
char1 = char1 + '0';
Loc[j]=char1;
j++;
/*means use a bitwise AND to take the bottom four bits from the byte,
0x0F is 00001111 in binary*/
char1 = Tmp[i] & 0x0f;
if (char1 >9)
{
char1 = char1 - 0xa;
char1 = char1 + 'A';
}
else
char1 = char1 + '0';
Loc[j]=char1;
j++;
Loc[j]=0;
}
Temp 和 Loc 是字符串缓冲区。已定义并有数据。它无法正常工作。我正在从某个文件(示例 fread)中读取 temp 中的数据。它在特定点停止读取文件。如果我先改变
0xf0
至
0x0f
以下是文件的读取方式:
BytesRead = fread (Tmp,1,Bytes,PrcFile);
然后它读取整个文件。我找不到丢失的东西。你能在这方面帮助我吗?谢谢