Searching \ for '2 digit BCD to binary conversion' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=digit+bcd+binary
Search entire site for: '2 digit BCD to binary conversion'.

Truncated match.
PICList Thread
'2 digit BCD to binary conversion'
1998\04\04@114643 by TORRENS SR

flavicon
face
has anyone got a bit of code that would do 2 digit BCD to binary
conversion ?

1998\04\04@121840 by Mike Keitz

picon face
On Sat, 4 Apr 1998 17:47:38 GMT TORRENS SR <spam_OUTr139aTakeThisOuTspamSMSERVER2.ULST.AC.UK>
writes:
>has anyone got a bit of code that would do 2 digit BCD to binary
>conversion ?
>
Here, you have to have the 2 BCD digits in the low 4 bits of bcdh and
bcdl, with the high 4 bits all zero.  The result is place in bin.  Note
that it could be modified to just reuse one of the bcd locations to store
the binary result.

       movfw   bcdh
       movwf   bin             ;bin = bcdh
       clrc
       rlf     bin,f           ;bin = bcdh * 2
       rlf     bin,f           ;bin = bcdh * 4
       addwf   bin,f           ;bin = bcdh * 4 + bcdh = bcdh *
5
       rlf     bin,f           ;Now bin = bcdh * 5 * 2 = bcdh *
10
       movfw   bcdl
       addwf   bin,f           ;Finally bin = bcdh*10 + bcdl

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

1998\04\05@213923 by Regulus Berdin

flavicon
face
Considering 2digit bcd is in one byte, here is my solution (may have some
bugs):

       swapf   BCD,w
       andlw   0x0f                    ;w = bcdh
       movwf   RESULT                  ;result = bcdh
       addwf   RESULT,w                ;w = bcdh*2
       addwf   RESULT,f                ;result = bcdh + w
       addwf   RESULT,f                ;result = (bcdh + w) + w = bcdh*5
       rlf     RESULT,f                ;result = result * 2 = bcdh*10
                                       ;no need to clear carry flag due
                                       ;  previous adds which cannot have overf
low
       movf    BCD,w
       andlw   0x0f                    ;w = bcdl
       addwf   RESULT,f                ;result = bcdh*10 + bcdl

Reggie

1998\04\06@172431 by Scott Dattalo

face
flavicon
face
Regulus Berdin wrote:
>
> Considering 2digit bcd is in one byte, here is my solution (may have some
> bugs):
>
>         swapf   BCD,w
>         andlw   0x0f                    ;w = bcdh
>         movwf   RESULT                  ;result = bcdh
>         addwf   RESULT,w                ;w = bcdh*2
>         addwf   RESULT,f                ;result = bcdh + w
>         addwf   RESULT,f                ;result = (bcdh + w) + w = bcdh*5
>         rlf     RESULT,f                ;result = result * 2 = bcdh*10
>                                         ;no need to clear carry flag due
>                                         ;  previous adds which cannot have
overflow
>         movf    BCD,w
>         andlw   0x0f                    ;w = bcdl
>         addwf   RESULT,f                ;result = bcdh*10 + bcdl

Good Reggie, but how about this


   rrf   bcd,W
   andlw 01111000b  ;W = tens*8
   movwf temp
   clrc
   rrf   temp,f     ;W = tens*4
   rrf   temp,f     ;W = tens*2
   subwf bcd,W      ;W = tens*16 + ones - tens*8
                    ;W = tens*8 + ones
   addwf temp,W     ;W = tens*10 + ones


Or if you have the BCD digits in the lower nibbles of the
two bytes bcdl and bcdh (per Keitz's naming convention) then
consider something Andy posted a long time ago:

   clrc
   rlf   bcdh,W     ;W = tens*2
   swapf bcdh,F     ;tens = tens*16
   rrf   bcdh,F     ;tens = tens*8
   addwf bcdh,W     ;W = tens *10

   addwf bcdl,W     ;W = tens*10 + ones

or if you wish to preserve the bcd digits:

   swapf bcdh,W     ;W = tens*16
   movwf temp
   clrc
   rrf   temp,F     ;temp = tens*8
   rlf   bcdh,W     ;W = tens*2
   addwf bcdl,W     ;W = tens*2 + ones
   addwf temp,W     ;W = tens*10 + ones

None of these routines have been tested. But all of my free
code is either untested or uncommented. :)

Scott

1998\04\06@200608 by Regulus Berdin

flavicon
face
----------
> Good Reggie, but how about this
>
>
>     rrf   bcd,W
>     andlw 01111000b  ;W = tens*8
>     movwf temp
>     clrc
>     rrf   temp,f     ;W = tens*4
>     rrf   temp,f     ;W = tens*2
>     subwf bcd,W      ;W = tens*16 + ones - tens*8
>                      ;W = tens*8 + ones
>     addwf temp,W     ;W = tens*10 + ones
>

Very optimized! Only the comments has a bug :)

       rrf temp,f      ;temp = tens*4
       rrf temp,f      ;temp = tens*2

Reggie

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...