访问电脑版页面

导航:老古开发网手机版其他

码制转换程序

导读:
关键字:
#include
#include
#include
#include
/**此宏定义摘自51bbs Youth发表***/
#define LongToBin(n) \
(\
((n >> 21) & 0x80) \
((n >> 18) & 0x40) \
((n >> 15) & 0x20) \
((n >> 12) & 0x10) \
((n >> 9) & 0x08) \
((n >> 6) & 0x04) \
((n >> 3) & 0x02) \
((n ) & 0x01) \
)

#define Bin(n) LongToBin(0x##n##l)

/********** HEX转BCD******/
/***bcd_data(<0x255,>0)***/
unsigned char BCD2HEX(unsigned int bcd_data)
{
unsigned char temp;
temp=((bcd_data>>8)*100) ((bcd_data>>4)*10) (bcd_data&0x0f);
return temp;
}
/********** HEX转BCD******/
/***hex_data(<0xff,>0)****/
unsigned int HEX2BCD(unsigned char hex_data)
{
unsigned int bcd_data;
unsigned char temp;
temp=hex_data%100;
bcd_data=((unsigned int)hex_data)/100<<8;
bcd_data=bcd_data temp/10<<4;
bcd_data=bcd_data temp%10;
return bcd_data;
}

void main(void)
{
unsigned int c;

c= Bin(10101001); // then c = 0xA9
c=BCD2HEX(0x255); file://255 转成HEX为0xff
c=HEX2BCD(0xff); file://0xff 转成BCD码为 255
}


来源:   作者:  2005/10/16 0:00:00
栏目: [ ]

相关阅读

安森美推出新的高功率图腾柱PFC控制器,满足具挑战的能效标准

动态功耗低至60μA/MHz!助力设备超长续航,首选国民技术低功耗MCU!