1

I have problem: you know the 2s Complement so you can get the negative number of a positive one with the reverse and adding a one. e.g.

8 Bit
121 = 0111 1001
 1st= 1000 0110
  +   0000 0001
      ---------
      1000 0111 --> -121 

So now if we have a -0

a zero looks as 8 bit

0000 0000

so a minus 0 should look

 1111 1111 + 0000 0001
= 10000 0000

but that is 512

so I think that I've misunderstood something

Cœur
  • 37,241
  • 25
  • 195
  • 267
ThePom
  • 95
  • 3
  • 13
  • 2s complement is typically for fixed-width numbers. Otherwise, how do you know when to stop inverting bits in the first step? And how would you know which bit is the most significant bit? – awksp May 19 '14 at 21:48
  • `1111 1111 + 0000 0001` in 8 bit is `0000 0000` the ninth bit is lost because there is no place from it – Serpiton May 19 '14 at 21:54
  • @user3580294 I think that the '8 bit' is telling the width you re right otherwis... it also should stop or not because you don't consider the next 00 or not – ThePom May 19 '14 at 21:54
  • @Serpiton so is the 2s Complement of a negativ number the positiv one or... or is it the s2s complement of -0-> -0? – ThePom May 19 '14 at 21:57

2 Answers2

1

To expand my previous comment to the question

1111 1111 + 0000 0001 in 8 bit is 0000 0000, the ninth bit is lost because there is no place from it.

And, yes the complement of a negative is a positive

-121 = 1000 0111
 1st = 0111 1000
   +   0000 0001
       ---------
       0111 1001 --> 121 

Think of them as a circle, at one point there is 0, adding 1 at a time you go up to the opposite point (128 in 8 bit) at that point the sign is switched and the absolute value begin to decrease, e.g.: 128 + 1 = -127, as you continue to add 1 the value go back to 0 and the circle is completed.

So given a number of bit, you only have that much bit, no more, and if you want the value to be signed you really have only x-1 bit for the value, as the most significant bit is used for the sign (0 -> +; 1 -> -)

Serpiton
  • 3,676
  • 3
  • 24
  • 35
0

1 0000 0000b is 256, not 512. Truncated to 8 bits, it's 0.

This is because with two's complement, zero is zero. There is no positive or negative zero.

Compare this to one's complement or sign bit, where positive zero and negative zero are different values.

that other guy
  • 116,971
  • 11
  • 170
  • 194