BCD码转十进制C语言实现

#include <stdio.h>
#include <stdlib.h>
#define uchar unsigned char  
uchar BCD_Decimal(uchar bcd) ;
int main(void)
{
     uchar ch = 0x20 ; 
     uchar dec = BCD_Decimal(ch) ; 
     printf("dec = %d\n",dec);
     while(1){
        ;         
     }
     return 0 ;   
} 


//BCD码转十进制函数,输入BCD,返回十进制
uchar BCD_Decimal(uchar bcd)
{
 uchar Decimal;
 Decimal=bcd>>4;
 return(Decimal=Decimal*10+(bcd&=0x0F));
}
运行结果:20

你可能感兴趣的:(BCD码转十进制C语言实现)