void d_charToHex(u8 c, u8* hex)
{
u8 value = c;
u8 highNibble = (value >> 4) & 0xF;
u8 lowNibble = value & 0xF;
hex[0] = (highNibble < 10) ? ('0' + highNibble) : ('A' + highNibble - 10);
hex[1] = (lowNibble < 10) ? ('0' + lowNibble) : ('A' + lowNibble - 10);
}
// 函数将字符串转换为十六进制字符串
void d_stringToHex(u8* input)
{
u8 inputLength = strlen(input);
u8 outputIndex = inputLength*2;
input[outputIndex--] = '\0'; // 添加字符串结束符
for (char i = (inputLength - 1); i > -1; i--)
{
u8 hex[2]; // 存储字符的十六进制表示,包括两个字符和一个结束符
d_charToHex(input[i], hex);
input[outputIndex--] = hex[1];
input[outputIndex--] = hex[0];
}
}
字符串转十六进制字符串-扩
于 2023-09-26 21:04:26 首次发布