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);
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);