8804 views|1 replies

1284

Posts

0

Resources
The OP
 

Commonly used code conversion BCD, HEX, BIN [Copy link]

Commonly used code conversion BCD, HEX, BIN
This post is from MCU
Personal signature呼呼...在校应届大四学生,代做电子类毕业设计(测量类、仪器类、控制类、无线通信类、电子产品类、界面设计类、纯论文类等等,一一俱全)。涉及各种单片机软硬件设计、电路模拟分析、FPGA、CPLD、ARM7/ARM9、LINUX、VB/VC++/QT界面等等。包过。。。欢迎咨询。Tel:13957160506。QQ:273437087
 

1284

Posts

0

Resources
2
 
#include #include #include #include #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); // c = 0xA9 c=BCD2HEX(0x255); //255 转成HEX为0xff c=HEX2BCD(0xff); //0xff 转成BCD码为 255 }
This post is from MCU
 
Personal signature呼呼...在校应届大四学生,代做电子类毕业设计(测量类、仪器类、控制类、无线通信类、电子产品类、界面设计类、纯论文类等等,一一俱全)。涉及各种单片机软硬件设计、电路模拟分析、FPGA、CPLD、ARM7/ARM9、LINUX、VB/VC++/QT界面等等。包过。。。欢迎咨询。Tel:13957160506。QQ:273437087
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list