转自:http://blog.csdn.net/sdwuyulunbi/article/details/4741721
在写程序时,经常需要进行BCD码和ASCII码的转换,下面是我常用的转换程序,如果大家有需要,直接调用就行了,呵呵!
unsigned char BCD2HEX(unsigned char bcd_data) //BCD转为HEX子程序
{
unsigned char temp;
temp=(bcd_data/16*10 + bcd_data%16);
return temp;
}
unsigned char HEX2BCD(unsigned char hex_data) //HEX转为BCD子程序
{
unsigned char temp;
temp=(hex_data/10*16 + hex_data%10);
return temp;
}