C语言十六进制字节转ASCII字符函数
将单个字节转化为两个ASCII字符进行显示,即一个字节转化为两个字节。如0x27,转化为'2' '7'两个字符。
uint16_t HexToASCII(uint8_t data_hex)
{
uint8_t data_ASCII_H;
uint8_t data_ASCII_L;
uint16_t data_ASCII;
data_ASCII_H = ((data_hex >> 4) & 0x0F);
data_ASCII_L = data_hex & 0x0F;
if(data_ASCII_H <= 9)
{
data_ASCII_H += 0x30;
}
else if((data_ASCII_H >= 10) && (data_ASCII_H <= 15))
{
data_ASCII_H += 0x37;
}
if(data_ASCII_L <= 9)
{
data_ASCII_L += 0x30;
}
else if((data_ASCII_L >= 10) && (data_ASCII_L <= 15))
{
data_ASCII_L += 0x37;
}
data_ASCII = (((data_ASCII_H & 0x00FF) << 8) | data_ASCII_L);
return data_ASCII;
}
相关推荐
cdyun0 2018-07-09
stulen 2020-08-15
Caleb0 2020-05-01
Caleb0 2020-05-01
liulufei 2020-02-22
Joymine 2020-02-01
csde 2019-08-16
wyqwilliam 2019-10-20
tianqi 2018-01-28
chhandsome 2016-12-08
86427217 2016-08-15
TesterJingel 2015-08-04
LychieFan 2010-11-08
zljiaa 2018-01-28
80467305 2019-06-26
mianhuantang 2011-09-07
wangdoudou0 2011-08-08
gallon00 2012-10-31
88241243 2014-08-29