Searching \ for 'Binary to ASCII conversion' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=binary+ascii+conversion
Search entire site for: 'Binary to ASCII conversion'.

Truncated match.
PICList Thread
'Binary to ASCII conversion'
1999\03\19@083906 by juha tuomi

flavicon
face
Hi !
I have a little problem. I should convert a 16 bit value to
ASCII-characters.

2 bytes  ->  '9' '9' '9' '9'   four separate ASCII-chars.

The 16 bit value can not be greater than 9999, so 4 digits will be enough.
Do you have any solution?

Greetigs,  Juha

1999\03\19@084742 by WF AUTOMACAO

flavicon
face
juha tuomi wrote:
>
> Hi !
> I have a little problem. I should convert a 16 bit value to
> ASCII-characters.
>
> 2 bytes  ->  '9' '9' '9' '9'   four separate ASCII-chars.
>
> The 16 bit value can not be greater than 9999, so 4 digits will be enough.
> Do you have any solution?
>
> Greetigs,  Juha

Sucessive divisions by 10...

See the remainder for each divisions, push on stack, make a "counter" of
divisions until you have a zero on division...

Pop "counter" times, add 0x30, and print it!

Miguel

1999\03\19@084746 by Clark, John

picon face
Just copy each nibble to a separate byte and OR with 0x30.


John Clark, Software Engineer
spam_OUTJohnCTakeThisOuTspaminter-intelli.com
(317) 715-8175 (voice & fax)

Interactive Intelligence, Inc.
3500 DePauw Blvd., Suite 1060
Indianapolis, IN  46268-1136
http://www.inter-intelli.com

> {Original Message removed}

1999\03\19@094031 by Stefan Sczekalla-Waldschmidt

flavicon
face
> > Hi !
> > I have a little problem. I should convert a 16 bit value to
> > ASCII-characters.
> >
> > 2 bytes  ->  '9' '9' '9' '9'   four separate ASCII-chars.
> >
> > The 16 bit value can not be greater than 9999, so 4 digits will be enough.
> > Do you have any solution?
> >
> > Greetigs,  Juha

Do a BCD adjust to each nibble starting with the least significant
nibble.

After you've done this, you just need to seperate each nibble
and add the appropriate offset to nibble to get the ascii value.

Kind regards,

       Stefan

1999\03\19@105250 by Wagner Lipnharski

picon face
juha tuomi wrote:
> Hi !
> I have a little problem. I should convert a 16 bit value to
> ASCII-characters.
> 2 bytes  ->  '9' '9' '9' '9'   four separate ASCII-chars.
> The 16 bit value can not be greater than 9999, so 4 digits will be enough.
> Do you have any solution?

It is not clear if your 16 bits value is in hexadecimal or already in
decimal.  According to your text about that the 16 bits value can not be
greater than 9999, it looks like it is in bcd (binary coded decimal), is
that right?

If it is in decimal, well, just a nibble separation to the right, AND
0Fh, OR 30h, you get the ascii code for the digit.

if it is in hexadecimal, it is all wrong, first because 9999h (39321
decimal) will not fit in only 4 decimal digits.

Wagner

1999\03\19@185416 by Regulus Berdin

picon face
Hi,

Take a look at my website below.  There exists a 16 bit binary to BCD
conversion for 0 to 65535 using bcd div by 2 method.  The result is a
packed BCD.  You should process after to unpack it and convert it ASCII
by:

       call    bin2bcd         ;convert to packed bcd

       swapf   bcd2,w          ;get thousands in lower nibble
       andlw   0x0f            ;mask hundreds
       addlw   0x30            ;convert to ASCII
       movwf   d1000           ;save result
       movf    bcd2,w          ;get hundreds
       andlw   0x0f            ;mask thousand
       addlw   0x30            ;convert to ASCII
       movf    d100            ;save

       swapf   bcd3,w          ;get tens in lower nibble
       andlw   0x0f            ;mask ones
       addlw   0x30            ;convert to ASCII
       movwf   d1000           ;save result
       movf    bcd3,w          ;get ones
       andlw   0x0f            ;mask tens
       addlw   0x30            ;convert to ASCII
       movf    d100            ;save


But using John Payson's routine, which is much faster and the result is
already unpacked is the best way.  Adding 0x30 to the results will
convert it to ASCII easily.

;-------------------------------------------------------------------
;
; Binary-to-BCD.  Written by John Payson.
;
; Enter with 16-bit binary number in NumH:NumL.
; Exits with BCD equivalent in TenK:Thou:Hund:Tens:Ones.
;

       org     $0010   ;Start of user files for 16c84

NumH:   ds      1
NumL:   ds      1
TenK:   ds      1
Thou:   ds      1
Hund:   ds      1
Tens:   ds      1
Ones:   ds      1

Convert:                        ; Takes number in NumH:NumL
                               ; Returns decimal in
                               ; TenK:Thou:Hund:Tens:Ones
       swapf   NumH,w
       andlw   $0F             ;*** PERSONALLY, I'D REPLACE THESE 2
       addlw   $F0             ;*** LINES WITH "IORLW 11110000B" -AW
       movwf   Thou
       addwf   Thou,f
       addlw   $E2
       movwf   Hund
       addlw   $32
       movwf   Ones

       movf    NumH,w
       andlw   $0F
       addwf   Hund,f
       addwf   Hund,f
       addwf   Ones,f
       addlw   $E9
       movwf   Tens
       addwf   Tens,f
       addwf   Tens,f

       swapf   NumL,w
       andlw   $0F
       addwf   Tens,f
       addwf   Ones,f

       rlf     Tens,f
       rlf     Ones,f
       comf    Ones,f
       rlf     Ones,f

       movf    NumL,w
       andlw   $0F
       addwf   Ones,f
       rlf     Thou,f

       movlw   $07
       movwf   TenK

                       ; At this point, the original number is
                       ; equal to
                       TenK*10000+Thou*1000+Hund*100+Tens*10+Ones ;
                       if those entities are regarded as two's
                       compliment ; binary.  To be precise, all of
                       them are negative ; except TenK.  Now the
                       number needs to be normal- ; ized, but this
                       can all be done with simple byte ; arithmetic.

       movlw   $0A                             ; Ten
Lb1:
       addwf   Ones,f
       decf    Tens,f
       btfss   3,0
        goto   Lb1
Lb2:
       addwf   Tens,f
       decf    Hund,f
       btfss   3,0
        goto   Lb2
Lb3:
       addwf   Hund,f
       decf    Thou,f
       btfss   3,0
        goto   Lb3
Lb4:
       addwf   Thou,f
       decf    TenK,f
       btfss   3,0
        goto   Lb4

       retlw   0

regards,
Reggie

juha tuomi wrote:
{Quote hidden}

--
e-mail: .....rberdinKILLspamspam@spam@bigfoot.com
ICQ#:   31651436
URL:    http://www.bigfoot.com/~rberdin

1999\03\22@032028 by Dr. Imre Bartfai

flavicon
face
Hi,
the most efficient way is if you converts it to BCD beforehand. Then
follow the advice below. There is the AN526 for this. I use it. The
routine calls B16TOBCD.ASM.
Good luck!
Imre

On Fri, 19 Mar 1999, Clark, John wrote:

{Quote hidden}

> > {Original Message removed}

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