Talk:Two's complement

From Wikipedia, the free encyclopedia

To-do list for Two's complement: edit · history · watch · refresh
  • Describe how to extend precision (using sign extension)
  • Explain multiple precision two's complement arithemetic
  • Describe multiplication and division of two's complement numbers
  • Describe special considerations with left/right shifting
  • Consider adding a short history of the move to two's complement representation in modern computers

Can we merge this with signed number representations? which is not too long yet and there are some overlap between that and this. -- Taku 23:23, Jul 31, 2004 (UTC)

I disagree; there may be some overlap but the pages have different purposes. Signed number representations compares different representations; this describes one of them in detail. --Rick Sidwell 03:26, 13 Apr 2005 (UTC)

Contents

[edit] Overly verbose example

In showing that -95 is congruent to 161 (mod 256), there's an example that shows "−95 + 256 = −95 + 255 + 1 = 255 − 95 + 1 = 160 + 1 = 161". What's with the verbosity? Would "-95 + 256 = 161" not work just as well?

The point of the example is to illustrate the binary subtraction. The one's complement of x
is just (255 - x). So we need the 255. Compare to the binary example immediately following.
Scottcraig 21:25, 15 July 2005 (UTC)

[edit] Re: Why it works

Ooh. All I can say is that two's complement only has to be actually implemented where the resulting numbers are actually used; a simple addition or subtraction module wouldn't care a bit (no pun intended). --Ihope127 01:49, 25 August 2005 (UTC)

[edit] Binary notation

The article uses a strange form of binary notation:

−64 = 1100 00002

The subscript 2 is usually reserved for the binary numeral system, rather than any old binary represenation. As I understand it, the above binary is how to write 192 in (mathematical) binary. Is there another way we could indicate the numbers are just binary, without using the "normal" binary counting system? —Pengo 07:29, 12 September 2005 (UTC)

I agree, though I don't have a better suggestion. --63.85.132.5 13:00, 9 March 2006 (UTC)


I'm not sure I understand what Pengo means by "any old binary represenation" or "indicate that numbers are just binary" but I'm no native English speaker.

However, why not write

−64 = 1100 00002's
−63 = 1100 00001's
192 = 1100 00002

It wouldn't be much extra work. HenkeB 01:31, 7 June 2006 (UTC)

[edit] Intro changes and the concise summary

I made a few changes to the intro to try to make it more clear. The main one is the addition of the concise summary:

In an n-bit binary number, the most significant bit is usually the 2n-1s place. But in the two's complement representation, its place value is negated; it becomes the −2n-1s place and is called the sign bit.

When I discovered this, it instantly clarified everything about two's complement for me. I'm interested to know if it does the same for you, or if there is an easier way to present that idea.

I know of 3 other ways to 'get to' two's complement:

  1. the classic 2^N-b way
  2. define -1 as the bit pattern that gives you 0 when you add it to +1
  3. as a nice specialization of excess notation

Perhaps someday someone can write these up in detail here.

Ken 05:41, 2 February 2006 (UTC)Ken

[edit] calculation trick

One of my teachers mentioned a trick that was pretty useful. In calculating two's compliment, one finds the least significant 1, and flips all the bits more significant that that bit (ie. find the first 1, and flip the bits above it - but don't flip the first 1). This should have a picture to go along with it, and I don't have time now. Fresheneesz 22:47, 24 May 2006 (UTC)

[edit] Carry Bit/OverFlow Bit

I believe this page needs to be revamped. Their are a lot of inconsitentcies regarding the MSB. First of all the (Most Significant Bit (MSB) entry says that it is the highest bit of a binary value. But then it said to be the sign bit.

But more importantly, the carry bit tells you nothing in two's compliment. The overflow bit occurs when the addition of 2 positive numbers yields a negative, or the addition of two negative numbers gets a postive.

Also there is incorrect information regarding the XOR statement, the carry bit and the sign bit to do not determine the overflow bit. I shall prove this by contradiction.

 01 1111
+10 1010
 -------
 00 1001 C=1  S= 0, but V=0

Cleary the XOR argument doesn't work --NMocho 14:49, 23 July 2006 (UTC)

The article is correct regarding the XOR statement. It isn't the carry and sign bits that determine overflow, but the carry into and out of the sign bit. In this case, they are both 1, so there is no overflow. The carry out of the sign bit goes into the carry bit, and NMocho is correct that this tells you nothing in two's complement. The carry bit is useful for multi-precision addition, when the msb is an ordinary bit in the middle of a number, not the sign bit. The carry into the sign bit is not directly accessible in typical computers; it is XOR'ed with the carry out of the sign bit and stored in the overflow bit, which itself is not useful until a multi-precision addition is complete. So after any given addition operation, either the carry bit or the overflow bit is useful depending on whether it was an intermediate or final addition, but not both.
Multi-precision arithmetic isn't covered in the article. Perhaps it should be, although it isn't specific to two's complement. --Rick Sidwell 15:33, 29 July 2006 (UTC)

[edit] Explanation disorganized

It seems that at some point the text was re-arranged carelessly. In the section Explanation, reference is made to "as we did when we counted backwards", apparently referring to some preceding text that has been removed. Also there's a reference to "the aforementioned overflow checks", again apparently referring to text that has been (re)moved. At this point, I stopped reading.

 Ferdinand Pienaar 09:56, 31 October 2006 (UTC)

[edit] Gosper extending two's complement into infinity

Would a link to the p-adic numbers be appropiate here, considering that while meaningless in normal number space, Gosper's proof actually IS correct for the 2-adic numbers? I know I once indepently got the idea of p-adic numbers from extending two's complement, though I never did much with it. -- Milo