zl程序教程

您现在的位置是:首页 >  其他

当前栏目

BCD码与十进制转换

2023-09-27 14:29:24 时间

BCD码转十进制

#include <stdint.h>

/* convert from BCD to dec */
uint8_t dec  = (bcd  >> 4) * 10 + (bcd  & 0x0f);

十进制转BCD码

#include <stdint.h>

/* convert from dec to BCD */
uint8_t bcd = ((dec / 10) << 4 & 0xf0) + ((dec % 10) & 0x0f);