# PICMicrocontoller Radix MathMethod

### Packed BCD to 16 bit binary conversion

```#include
cblock 0x0C
bcd0, bcd1, bcd2
lo, hi
counter
endc

mov	macro __x, __y
movlw __x
movwf __y
endm

mov 0x06, bcd2
mov 0x55, bcd1
mov 0x35, bcd0
call bcd2bin16
nop

;*******************************************************************************
;    Input: packed BCD in bcd2:bcd1:bcd0 (modified!)
;           bcd0 = tens:ones
;	    bcd1 = thou:hund
;           bcd2 = 0:tenk
;   Output: 16 bit binary in hi:lo
;Temporary: counter
;     Size: 23 instructions
;   Timing: 2+2+16*(6+12+3)-1+2=341 instruction cycles
;
; Notes: The routine uses BCD division by 2. Each iteration
;        the LSB of BCD value (which coincides with correspondent
;        binary bit) is shifted to output and BCD value is
;	 divided by 2. To do the division, BCD is shifted right
;        once and corrected. Correction: if MSB of a nibble is set,
;	 subtract 3 from it.
;
;January 22, 2001 by Nikolai Golovchenko
;*******************************************************************************
bcd2bin16
movlw 16
movwf counter
bcd2bin16loop
clrc
rrf bcd2, f
rrf bcd1, f
rrf bcd0, f
rrf hi, f
rrf lo, f

clrw
btfsc bcd0, 3
iorlw 0x03
btfsc bcd0, 7
iorlw 0x30
subwf bcd0, f
clrw
btfsc bcd1, 3
iorlw 0x03
btfsc bcd1, 7
iorlw 0x30
subwf bcd1, f

decfsz counter, f
goto bcd2bin16loop
return
;*******************************************************************************

END
```

 file: /Techref/microchip/math/radix/bcd2bin16.htm, 1KB, , updated: 2006/5/18 18:58, local time: 2018/10/16 06:25, owner: NG--944, TOP NEW HELP FIND:  54.80.87.166:LOG IN

 ©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?Please DO link to this page! Digg it! / MAKE! /  Packed BCD to 16 bit binary conversion

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here:
if you want a response, please enter your email address:
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

 PICList 2018 contributors: o List host: MIT, Site host massmind.org, Top posters @20181016 RussellMc, Van Horn, David, Sean Breheny, David C Brown, Bob Blick, Neil, Isaac M. Bavaresco, John Gardner, Harold Hallikainen, Denny Esterline, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr.

.