BCD碼與十進制轉換

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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章