BCD to BINARY Converter?

fingerstyle86

New Member
His guys i am new here, I would just like to ask does anyone know what commands i can use to convert BCD to BINARY or vice versa?

Thanks!
 

westaust55

Moderator
There is no direct command.

Depending how many variables you have available and whether you want the result in a single byte or each digit in a separate byte, there are several options.

1 You can use the BCDTOASCII and then subract $30 (ie "0") from each digit

BCDTOASCII b0, b1, b2 ; BCD value in b0, tens into b1, units into b2
b1 = b1 - $30
b2 = b2 - $30
b0 = b1 * 10 + b2

or

2. in simple maths using 2 varaibles
if b0 = 59 BCD and you want 59 decimal or $3B (hex)
b1 = b0 / 16 * 10
b0 = b0 AND $0F + b1
 
Last edited:
Top