In assembler (PIC) how do I convert BCD to Binary... Plenty of sites show the reverse. I want to convert and eight digit BCD number to its binary equivalent...
If you're talking about a packed BCD byte which is "tens" * 16 + "ones" then you just need to convert it to "tens" * 10 + "ones", perhaps something like this;
Regards, Mike
Code:
BCD_to_Bin
movwf Test ; save Test value |B0
swapf Test,W ; swap nybbles (into W) |B0
andlw h'0F' ; mask swapped tens digit |B0
movwf Temp ; put it in a work file |B0
addwf Temp,W ; W = 2 * tens |B0
addwf Temp,F ; F = 3 * tens (C = 0) |B0
rlf Temp,W ; W = 6 * tens |B0
subwf Test,W ; 16 * tens + ones - 6 * tens |B0
Yes its a packed byte that is... each nibble represents a power. eg 12312312 would be... 0001 0010 0011 0001 0010 0011 0001 0010. So in this case and what I am looking for is a 32 bit BCD number. Four bytes each with two nibbles each nibble representing one digit. The binary equivalent is "101110111101111011111000"
Mike how would you expand this to a 32bit conversion?