Hello,
neg -2147483648 becomes -2147483648 on my AMD X2 3800+ processor.
The integer range is: -2147483648 to 2147483647
Two's complement (negation?) is:
1. Invert all bits.
2. Add +1
Thus -2147483648 is represented as:
11111111111111111111111111111111
1. invert:
00000000000000000000000000000000
2. add +1:
00000000000000000000000000000001
However the outcome is:
11111111111111111111111111111111
Which is a wrong result ?!?
Ofcourse
00000000000000000000000000000001
Can be considered a wrong result as well... but at least it's a positive
wrap around.
Intel documents says nothing about this special case ?
Best would be to raise an exception ?
(Like divide by zero)
Bye,
Skybuck.
Rating: 0%, 0 votes
I'll use signed 8-bit, though this extends to any width (16, 32, 64, etc)
signed integers
NEG of 00000000 = 00000000
NEG of 11111111 = 00000001
NEG of 11111110 = 00000010
NEG of 10000010 = 01111110
NEG of 10000001 = 01111111
NEG of 10000000 = 10000000
Two values here have a NEG that is equal to itself.
For integer math, we know NEG of zero is always zero: -1 * 0 = 0
The other instance occurs when you're at the extreme negative value for the
width you are using. You can think of the computation in a few ways.
10000000 = -128 decimal. NEG of -128 dec = +128 dec, which would be
represented as 10000000 in binary. (The only reason we do not have a +128 in
signed 8-bit is because we have that defined as -128 already.)
Another way to look at it is this:
you have the following value ranges for signed 8-bit:
-127 decimal to -1 decimal
0
+1 decimal to +127 decimal
and a special overflow case: +/- 128
Never let your values reach this overflow case, and you'll be fine.
--
Bx.C / x87asm
...
Was this solution helpful? Show your Appreciation by rating it:
Rating: 0%, 0 votes
is one larger than the positive extreme, so negating it wouldn't fit
anyway. It's a special case. Live with it.
Was this solution helpful? Show your Appreciation by rating it:
Rating: 0%, 0 votes
The result remains negative though...
Weird result, I rather get an exception for it ;)
Bye,
Skybuck.
Was this solution helpful? Show your Appreciation by rating it:
Rating: 0%, 0 votes
Correction:
-2147483648 is actually represented as:
10000000000000000000000000000000
for signed integer format.
Let's do that again.
1. invert:
01111111111111111111111111111111
2. add +1:
10000000000000000000000000000000
Hmmm a different result :)
And a very funny result as well.
When following the two's complement negation this case remains exactly the
same.
I still consider it an errornous result :) and an exception should be raised
;)
LOL.
Bye,
Skybuck.
Was this solution helpful? Show your Appreciation by rating it:
Rating: 0%, 0 votes
Right.
Nope. It is: 10000000000000000000000000000000
Nope. It is: 01111111111111111111111111111111
Nope. It is: 10000000000000000000000000000000
Nope. It is: 10000000000000000000000000000000
Nope. It is as right as you can get it ;-)
Was this solution helpful? Show your Appreciation by rating it:
Post a New problem for Intel PRO/ 1000 MT 64BIT PCI- X QUAD
Email this problem

