Searching \ for '[PIC]: 32bit binary to ASCII conversion' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: '32bit binary to ASCII conversion'.

Exact match. Not showing close matches.
'[PIC]: 32bit binary to ASCII conversion'
2000\06\08@064801 by

Hi all
I have a project where I have to convert a 32 bit binary or hex number to
ASCII to be displayed on a LCD. Does some one on this list have done this
before, if so are you willing to share the solution with me or give me some
hints. I have done decimal to ASCII conversion no problem, but now my
project end up with a 32 bit number and then I have only very complicated
solutions.

\||||||/
_____oo0o__( o o )__o0oo_____
(_)

Henrik HolmgŒrd

I remember having to so this for integrating an ip address to a pic chip.
look for a project on the net called the worlds smallest web server. it uses
a seiko s7600a to connect a 16f84 to the internet. I'm sure it has some good
example code for dealing with 32bit addresses. if i remember right. I will
try to find the stuff I did myself and post it up soon.

{Original Message removed}
Henrik,

You have to convert the 32 bit binary number to a decimal
form and then convert the decimal form to ascii by adding
30h to each decimal digit.

I will run through the example for an 8 bit binary conversion
just to show you the principles involved. Using pseudo-code:

bin_to_dec:
;assume that upon entry 8 bit number is in bin_holder.
;assume that decimal result will be placed in dec3, dec2, dec1
;where dec3 is most significant decimal digit.
;uses temp holder <decnum>.
;upon exit bin_holder will be trashed.
CLEAR dec1 ;clear all decimal holders to zero.
CLEAR dec2
CLEAR dec3
ROTATE bin_holder RIGHT INTO CARRY ;bit0 <1> handled first...
IF CARRY=1
SET decnum=1
ENDIF
ROTATE bin_holder RIGHT INTO CARRY ;bit1 <2> handled next...
IF CARRY=1
SET decnum=2
ENDIF
ROTATE bin_holder RIGHT INTO CARRY ;bit2 <4> handled next...
IF CARRY=1
SET decnum=4
ENDIF
ROTATE bin_holder RIGHT INTO CARRY ;bit3 <8> handled next...
IF CARRY=1
SET decnum=8
ENDIF
ROTATE bin_holder RIGHT INTO CARRY ;bit4 <16> handled next...
IF CARRY=1
SET decnum=1
SET decnum=6
ENDIF
ROTATE bin_holder RIGHT INTO CARRY ;bit5 <32> handled next...
IF CARRY=1
SET decnum=3
SET decnum=2
ENDIF
ROTATE bin_holder RIGHT INTO CARRY ;bit6 <64>
IF CARRY=1
SET decnum=6
SET decnum=4
ENDIF
ROTATE bin_holder RIGHT INTO CARRY ;bit7 <128>
IF CARRY=1
SET decnum=1
SET decnum=2
SET decnum=8
ENDIF
RETURN

IF dec1 > 9
SUBTRACT 10d from dec1
ENDIF
RETURN

IF dec2 > 9
SUBTRACT 10d from dec2
ENDIF
RETURN

IF dec3 > 9
SUBTRACT 10d from dec3
ENDIF
RETURN

*** END OF PROGRAM ***

There are many ways to improve upon this code, but
this code fragment should give you an idea of what the
basic algorithm is like. For a full 32 bit implementation
you would need ADD routines for thousands, tens_thousands,
hundreds_thousands, millions, all the way up to
thousand_millions (billions to some of us).

That means 32 code segments to handle the 32 bits, and

Note that any decimal carry required is handled by the
GOTOs. This method is easy to understand, but in reality it
would be more efficient to implement the decimal additions
using indirect addressing via the FSR. That cuts the code
SIZE down a lot.

Note that the decimal ADD routines can also be used by

Fr. Tom McGahee

{Original Message removed}

---
jamesnewtonpiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}
There is a simple trick, outlined in the following pseudo-code for doing
this conversion:

ANSWER - an ascii decimal number - 10 digits
SOURCE - a 32-bit binary number

for I = 1 to 32
if high bit of SOURCE is set then
end if

SOURCE = SOURCE + SOURCE
next i

Note that the arithmetic on 'ANSWER' is done directly on the ASCII
representation.

carry = 0
for digit = 0 to 9
carry = 0
if (temp > '9') then
temp = temp - 10
carry = 1
end if
next digit

Bob Ammerman
RAm Systems
(high function, high performance, low-level software)

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