十六进制转ASCII
static char hex2ascii(u8 bhex)
{
if( bhex < 10 )
return (bhex + 0x30);
else
return (bhex + 0x37);
}
static void convert_hex_to_ascii(u8 *abbuff, u8 *abarray, int len)
{
for(int i=0; i<len; i++)
{
abbuff[2*i] = hex2ascii((abarray[i]>>4)&0x0F);
abbuff[2*i+1] = hex2ascii((abarray[i])&0x0F);
}
return;
}
ASCII转十六进制
static u8 ascii2hex( u8 bascii)
{
if( bascii <= '9' )
return ( bascii - '0' );
else if( bascii <= 'F' )
return ( 0x0a + bascii - 'A' );
else
return ( 0x0a + bascii - 'a' );
}
static void convert_ascii_to_hex(u8 *abbuff, u8 *abarray, int len)
{
for( int i=0; i<2*len; i+=2 )
{
abbuff[i/2] = ascii2hex(abarray[i])<<4;
abbuff[i/2] |= ascii2hex(abarray[i+1]);
}
return;
}
|