piclist 2000\06\09\080911a >
Thread: 32bit binary to ASCII conversion
www.piclist.com/techref/microchip/devices.htm?key=pic
picon face BY : Bob Ammerman email (remove spam text)



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

ANSWER <- '000000000'

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

   SOURCE = SOURCE + SOURCE
next i

Note that the arithmetic on 'ANSWER' is done directly on the ASCII
representation.
For example, to compute ANSWER + ANSWER:

carry = 0
for digit = 0 to 9
   temp = ANSWER[digit]+ANSWER[digit]+carry-'0'
   carry = 0
   if (temp > '9') then
      temp = temp - 10
      carry = 1
   end if
   ANSWER[digit] = ANSWER[digit]+ANSWER[diit
next digit

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

<019b01bfd20b$ad3b96a0$1d9b9cd1@ramdell> 7bit

See also: www.piclist.com/techref/microchip/devices.htm?key=pic
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) 32bit binary to ASCII conversion

month overview.

new search...