HEX与ASCII之间装换
Posted 珵诩媛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HEX与ASCII之间装换相关的知识,希望对你有一定的参考价值。
static const char bcd_ascll[20]={0x30,0x31,0x32,0x33,0x34,
0x35,0x36,0x37,0x38,0x39,
0X41,0X42,0X43,0X44,0X45,0X46};
const char ascll_bcd[25]={ 0x00,0x01,0x02,0x03,0x04,0x05,
0x06,0x07,0x08,0x09,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0A,
0X0B,0X0C,0X0D,0X0E,0X0F};
将 Data = 0x42转换成 ASCII:
AsciiData[0] = bcd_ascll[((bcd_ascll>>4)&oxf)] = 0x34
AsciiData[1] = bcd_ascll[((bcd_ascll)&oxf)]; = 0x32
将 AsciiData= {0x34,0x35}转换成 BCD:
Data = ascll_bcd[((AsciiData[0]-0x30)<<4)] = 0x40;
Data += ascll_bcd[((AsciiData[1]-0x30))] = 0x45;
以上是关于HEX与ASCII之间装换的主要内容,如果未能解决你的问题,请参考以下文章