Convert Binary to BCD

How can we convert a binary number into BCD number directly and vice-versa, without converting it into any other number system?

Questions by pawannarang007

Showing Answers 1 - 1 of 1 Answers

uzipereg

  • Jul 30th, 2011
 

It depends on the range. An algorithm can be used.

For a number in the range of 0 to 19 (decimal), the following algorithm can be used:

if a<10
a_BCD=a;
else if a<20
a_BCD=a+0x06;
end

for example if a=0x0E, then a_BCD=0x0E+0x06=0x14, which is the BCD representation of 0x0E.

This could be generalized for a number in the range of 0 to 99: a_BCD=a+n*0x06, where 10*n<=a<10*(n+1).

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions