Negating Zero

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Negating Zero

buster_the_dog
"To obtain the code of -x from the code of x... flip all the bits of x and add 1 to the result."

when I try to do this to zero in my ALU, it doesn't work, I always end up back at zero

Example

0000
Not
1111
Inc
0000

The extra one overflows. Am I doing something wrong? The book also says "Bit-wise negation of zero gives the 2’s complement code of -1.", so negating zero should end up with -1.

Reply | Threaded
Open this post in threaded view
|

Re: Negating Zero

cadet1620
Administrator
You are not doing anything wrong.

-0 and 0 are the same number so they have the same binary representation.

The confusion is the phrase "bit-wise negation"  which is the Boolean Not operation applied to each bit.  Wherever you read bit-wise negation, think not.

The ALU example you quote is explaining how the -1 is generated in the ALU for the x-1 operation.

The nx and ny control signals are "not x" and "not y". With zy=1 and ny=1, the y input to the adder is not(0). This is -1.

--Mark