08M2 and BCD bytes

sdscott

New Member
I am attempting to INC/DEC a BCD byte variable within my picaxe08m2 code. I could convert to binary using BCDTOBIN, then inc binByte, then convert the variable-byte back to BCD using BINTOBCD; but I'm using the 08M2, which doesn't support these conversion commands.

A while ago I seen a post response from Hippy offering a clever snippet;
BCDTOBIN command~ binByte = bcdByte / 16 * $FFFA + bcdByte

My question is; How do I write the conversion back to bcdByte after I increment/decrement the binByte?

Thanks in advance.
 

AllyCat

Senior Member
Hi,

The reverse conversion is even easier :

BCDbyte = BINbyte / 10 * 6 + BINbyte because each "tens" digit has a "weight" of 16 instead of 10 (i.e. it is 6 larger)

Don't forget that for more than one byte (2 digits) you must handle the overflow (from 99) and underflow (back to 99) in binary, and carry correctly.

Cheers, Alan.
 
Top