piclist 2001\04\05\050808a >
Thread: clever rounding out there ?
www.piclist.com/techref/microchip/devices.htm?key=pic
flavicon
face BY : Roman Black email (remove spam text)



Kübek Tony wrote:

> 3: My current 'idea', try to 'extract' the ones and tens from the
>    input ( 24 bit ) and somehow use it to round with. Sofar
>    i've managed to extract it but don't know really if this is the way
>    to go. I'm using about 200-300 cycles for the extraction
>    and have the tens in one byte and the ones in another byte.


Tony, i've been thinking about this rounding off
thing and I hope i'm not annoying you with suggestions
but the topic is intriguing to me. :o)

I think the 10s and 1s solution would work, how about:

(example, round 24bit binary number to nearest decimal 50)

1. add 25 to the 24bit number.
2. extract the 10s and 1s digits.
3. if 10s is greater than 5 subtract 5 from it.
4. multiply 10s by 10 (simple lookup table, 5 bytes)
5. add 1s to 10s (this is now the 50 modulus)
6. subtract the modulus from the 24bit number

All of those are very quick to perform, apart
from step 2; the extracting of the 10s and 1s.
You said you have done this but 300 cycles on
an 18 series PIC seems a lot.

Have you looked for an algorithm that extracts
BCD digits from a binary number? If you could find
a good refined system for this and just use the
section that extracts the last two digits??
:o)
-Roman

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email STOPspamlistservspamSTOPspammitvma.mit.edu with SET PICList DIGEST in the body


<3ACC3546.1409@ezy.net.au> quoted-printable

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) clever rounding out there ?

month overview.

new search...