In a message dated 96-05-26 05:38:43 EDT, Clyde Smith-Stubbs wrote: >msullivan@vax.niobrara.com (Mark K Sullivan) wrote: >> >> I needed to divide a 2's complement number by 2 and I just thought of this >> quickie arithmetic shift. Stop me if you've heard it before... Too late >;) >> >> rlf MyVar,W ;copy sign to carry >> rrf MyVar ;shift and duplicate sign > >There is just one slight problem with using shifts to divide -ve >numbers. To illustrate: what happens to -1 when you do this? > >Try this code instead: > > btfsc MyVar,7 > incf MyVar > rlf MyVar,w > rrf MyVar > >-- You bring up an interesting point, Clyde. It's true that Mark's routine yields -1 as the result of dividing -1 by 2. 8^( But that could be seen as the desired result. 8^). It leaves an error of 1/2, but then that's true of *every* odd number in the input. Mark's routine also has the advantage of leaving the size of the output bins the same. That is, there are *exactly* two input numbers which yield any given output number. With your scheme, a result of -40H is given *only* by an input of -80H, while a result of 0 is given by *three* inputs: -1, 0, and 1. I'm sure there are applications where either one of these algorithms is more useful than the other! Integers are fun, eh wot?? Regards... Shel Michaels sbmichaels@aol.com http://members.aol.com/sbmichaels