bin2bcd.c#include <stdio.h>
int main()
{
int bin=123, bcd;
int n, dig, num, count;
num = bin;
count = 0;
bcd = 0;
for (n=0; n<4; n++) {
dig = num%10;
num = num/10;
bcd = (dig<<count)|bcd;
count += 4;
}
printf("binary: %d bcd: %x\n",bin,bcd);
return 0;
}
binary: 123 bcd: 123
Maintained by John Loomis, updated Mon Oct 17 22:16:23 2011