www.piclist.com/techref/microchip/devices.htm?key=pic

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)

See also: www.piclist.com/techref/microchip/devices.htm?key=pic