BCD to Binary

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BCD to Binary

2,804 Views
PabloA
Contributor II
Hi every body!.
 
I include in my proyect a Real Time Keeper that give me all time data in BCD format and I need to store  data in a RAM Buffer that is addressed with the hour data, but I can't use BCD format to address.
So any body know any way to convert BCD format to Binary? I need to convert BCD to binary from "0" to "23".
 
Thanks you for your interest.
 
Pablo.
Labels (1)
0 Kudos
2 Replies

363 Views
bigmac
Specialist III
Hello Pablo,
 
Assuming "packed BCD" format, with both decimal digits contained within the same byte, here is a possible C function -
 
byte BCDconvert (byte BCDval)
{
   return (((BCDval & 0x30) >> 4) * 10 + (BCDval & 0x0F));
}
 
Here is the same process written in assembler -
 
BCDconvert:
   lda   BCDval
   and   #$30
   nsa
   ldx   #10
   mul
   psha
   lda   BCDval
   and   #$0F
   add   1,sp
   ais   #1     ; Adjust stack pointer
   rts
   ; On exit, ACC contains the binary value
 
Regards,
Mac
 
0 Kudos

363 Views
PabloA
Contributor II
Dear Mac:
 
I work perfectly. Just what I need.
 
Thank you.
 
Best regards.
 
Pablo
0 Kudos