piclist 2001\04\02\095941a >
Thread: How to do 24bit Signed Addition/Substration Fixed point.
www.piclist.com/techref/microchip/devices.htm?key=pic
BY : James Lee Williams email (remove spam text)

Yes, as long as you consistently treat the numbers as 2's complement and
you
don't overflow the representable values.

Lets take a couple simple 8-bit examples to put your mind at rest:

10 + -1 == 9:

B'00001010' + B'11111111'  = B'00001001'

5 - 10 = -5

B'00000101' - B'00001010' = B'11111011'

Note that we ignore carries out of/borrows into the most significant
bit.

It works fine with any number of bits. (It better -- this is the basis
behind integer arithmetic on all modern microprocessors).

Ah, you say that as long as I don't overflow the values, Well this could
easily happen on the second math opertion.  You indicated the following:

5 - 10 = -5
B'00000101' - B'00001010' = B'11111011'

Now if I have to take this result and add it to say 20, then this would
immediately overflow and everything would go wako, am I correct?  This
two's complement stuff makes be nervous when doing it this way.  Do I
have to worry about the carry in this instance?  You are familiar with
Bresenham.  Would this make any difference to the results?

Regards,

James

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

<03A1C3D564C54F41AE049A641BAE0D8A070E5E@infoexch01.infoserver.no> 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) How to do 24bit Signed Addition/Substration Fixed point.

new search...