#include <stdio.h>
// BCD转二进制
int bcd_to_binary(int bcd_num) {
int binary_num = 0;
while (bcd_num > 0) {
binary_num = binary_num * 10 + (bcd_num % 16);
bcd_num /= 16;
}
return binary_num;
}
// 二进制转BCD
int binary_to_bcd(int binary_num) {
int bcd_num = 0;
while (binary_num > 0) {
bcd_num = (bcd_num * 10) + (binary_num % 10);
binary_num /= 10;
}
return bcd_num;
}
|