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

Actually it would matter when adding a positive integer with a negative

interger. For example,

If I where to take this equation x1-x2 -> x_destination.

Let x1 = 15 OR 0x000F

Let x2 = 105 OR 0x0069

-------------

If I didn't handle signed math, the result of this operation would be:

FFA6 which is 65446 in decimal form. This is clearly not the result of

this subtraction operation.

In order for me to get the correct result I have to decriment the result

if the carry bit is cleared for each of the two bytes. Indicating a

negative result. Then, I compliment the result in both low and upper

bytes. This yields me a 90 result and a signe of negative. This is the

correct result. Then, I IOR the MSB bit with one to indicate negative.

Again, to illustrate the difference between signed and unsigned would be

in simple addition. -5 + 10.

Let x1 = 10 (0000000000001010) or 0x000A

Let x2 = - 5(1000000000000101) or 0x8005

--------------

Simple adding these would give the following result.

0x800F OR (1000000000001111).

Now when we remove the sign bit to obtain the actual value we get

0x000F, which is clearly not the result of 10 + (-5).

So in short, the mechanics is not the same. There is definiatel some

special handling that has to take place to work with signed integers.

Regards,

James

{Original Message removed}

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