One solution to this problem is a stack orentated machine leads to one of the most elegant methods using recursion that I have ever seen. Lets see if I can remember how it goes... // provide a place to keep the dividend static int48 accumulator ; // this is a routine that divides the 48 bit integer pointed to by "pacc" by "divisor". // It leaves the quotent in place of the dividend and returns the remainder char * div48( int48* pacc, char divisor ) ; void print48bit( int48 number ) { accumulator = number ; if (accumulator < 0 ) { putch( '-' ) ; accumululator *= -1 ; } doprint() ; return ; void doprint( void ) { char remainder ; remainder = div48( &accumulater, 10 ) ; if ( accumulator ) doprint() ; putch( remainder + '0' ) ; } I just remembered where I saw this - K&R 2nd Ed. p87. My rendition is a little different, but pretty much the same. This version uses an automatic so you only have to divide once. Their routine pushes the 48 bit number on the stack, uses two divides and one modulus. ---> disclamer: below not tested - probably full of typos!! <-------- I would just unroll this technique for the pic. It does require some storage. In the pic we have to use linear storage since we don't have a stack. I can't think of any way around this as the printable number come out of the calculation backwards. (OK, OK, I'm waiting for the 69 postings to show me I'm wrong...:-> ). Requirements: 6 bytes for the 48 bit accumulator 17 bytes for the null terminated result string ( 15 digits + minus sign + null ) 2 bits for flags a routine "div48" that divides the accumulator by 10 and returns the remainder in W. "div48" also maintains a zero flag which is only set when the accumulator is zero. a routine "neg48" that takes the twos compliment of the number in the accumulator. result RES 17 ; accumulator RES 6 ; flags RES 1 ; zero48 equ 0 ; ; the accumulator is zero when set, maintained by div48 needminus equ 1 ; ; flag that we need to print a minus sign ; ; make a 48bit number into a printable string. ; Initial conditions: 48 bit integer loaded in the accumulator ; On return: ; FSR points a first character of null terminated string ; W contains the number of characters in the string ; print48bit ; point to the end of the string area movlw result+16 ; point after the last char movwf FSR ; clrf IND0 ; make the terminating null bcf flags, needminus btfss accumulator+5, 8 ; check for negative number goto loophere call negate48 ; ; this could be in-line bsf flags, needminus loophere call div48 ; divide by 10, get the remainder in W, set the zero flag addlw '0' ; convert to ascii decf FSR, F movwf IND0 ; store and move pointer btfss flags, zero48 ; check if accum is zero goto loophere ; not zero yet, do the next character btfss flags, needminus goto done movlw '-' ; ; put in the negative sign and move the pointer decf FSR, F movwf IND0 ; done movf FSR, W sublw result+16 ; this may be backwards, I can never rem ember which way the ; subtract works return ; At 01:31 PM 9/5/99 +0100, you wrote: >I have a challenge. I need to convert a 48-bit binary number (stored in 6 >consecutive memory registers) into an ASCII string (i.e. '0' to '9') which >will then get transmitted to a PC. The string will be up to 15 characters >long. > >I can do this by going first to BCD and then from BCD to ASCII (although >this may well not be the best way). Microchip have published "Binary 16 >to BCD" code in AN526, and I also have "B24toBCD" which is just an >extended version of the 16-bit program. It looks straightforward to >extend it further to 48 bits. > >The thing is, I'd simply be working "parrot fashion". I can't suss out >how the BCD-to-ASCII algorithm works! > >Can anyone explain in plain English the basic principle? > >Also, with a bit of luck that might allow me to work out how to avoid the >intermediate BCD stage altogether and go straight from binary to ASCII. >Or has anyone done that already? > >Thanks, > >Steve Thackery >Suffolk, England. >Web Site: http://www.btinternet.com/~stevethack/ > >"Having children is hereditary. If your parents didn't have any, neither >will you." - Henry Morgan > > Jim Ham, Porcine Associates (650)326-2669 fax(650)326-1071 "http://www.porcine.com"