Talk:Method of complements

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

[Untitled][edit]

I never really heard about Ten's complement, Nine's complement etc. until today, so I am probably not the one to tidy up this article. I found a decent brief explanation of them for anyone else who wants to try. Someone who's better at math, please give it a look. -- Wapcaplet 01:50, 7 Nov 2003 (UTC)


Part of the Nine's Complement section wasn't correct, so I posted a little note of what seems to be the solution. . . --Joeedh 08:56, 15 Sep 2004 (UTC)

  • Thanks, though usually comments such as this (notes to other contributors) should not be visible in the article; to make such comments invisible in the article, yet visible in the edit window, you can surround them with HTML comment tags: <!-- ... -->. I'm having trouble understanding what you mean by this comment, though. You mention that 873-100 does not give a correct answer (did you mean 773?): 100 complemented is 899; 873 + 899 = 1772; drop the initial "1", giving 772; add 1, giving the correct answer 773. If you meant that subtracting a number smaller than 100 produces a wrong answer, I don't think that's true either; for example, for 873-50, complement 50 = 949; 873 + 949 = 1822; drop the "1" = 822; add 1 to get 823, the correct answer. The first digit in the intermediate result will always be "1" (unless x < y, which is a special case discussed in the next section) so I see no difference between subtracting 1 from it, or removing it altogether - and it should always be dropped. -- Wapcaplet 18:27, 15 Sep 2004 (UTC)
  • Must have been an error in my code implementation. I'm using it for a infinite-precision integer library for a C++ class. Thanks for the tip.

Nine's vs. nines'[edit]

I don't think "nines' complement" is correct. The system works by finding the complement of each digit with respect to a value of nine, and there need not be multiple nines involved. The nine's complement of 3, for instance, is 6. It works similarly to two's complement, which works by finding each digit's complement with respect to the value 2. If there are no objections within a few days, I will revert. -- Wapcaplet 18:11, 18 Nov 2004 (UTC)

I strongly agree. But I notice that nothing has happened since November of last year. Do you want to do this or shall I? Rick Norwood 19:21, 12 September 2005 (UTC)[reply]
I think the text in the last paragraph of the Numeric Complements section is accurate. But I wrote it, so please correct it if not. I've only seen the topic addressed in one place, Knuth's The Art of Computer Programming (volume 2, section 4.1). See also Talk:Signed number representations. Logical as his argument seems to me, if another author has a different opinion, I'll consider it. Of course, language is what writers use, and a lot of them use nine's, whether Knuth agrees with it or not! --Rick Sidwell 01:49, 13 September 2005 (UTC)[reply]
Knuth is a man with strong opinions, some of them correct. Rick Norwood 14:32, 13 September 2005 (UTC)[reply]

Yeah, I guess it makes sense to follow the normal rules of English grammar. Complement with 9 == nine's complement, complement with multiple 9s == nines' complement. -- Wapcaplet 03:04, 14 September 2005 (UTC)[reply]

It's an interesting issue. The most common use is to put the apostrophe before the 's', and I noted that in the paragraph about the issue. But it isn't really an important part of the overall topic, so I removed the references to it elsewhere in the article. (Besides, to me "Knuth's apostrophe convention" describes his method of `quoting' in TeX, not his preference for naming radix complements.) --Rick Sidwell 14:59, 24 September 2005 (UTC)[reply]

There shouldn't be an apostrophe at all. It should be nines complement. It is not the complement belonging to a nine or a number of nines. It is the complement with respect to a bunch of nines. Gnomon (talk) 18:07, 5 March 2020 (UTC)[reply]

Computers don't use two's complement for subtraction![edit]

I removed the following statement:

One practical application of the method of complements is for performing subtraction in a computer microprocessor which uses the binary numeral system. Binary computers typically employ the two's complement for the operation of subtraction.

Computers do use two's complement for representing numbers; it makes addition and subtraction of signed integers a lot easier. But they don't subtract by complementing and adding as described in this article; they subtract using subtraction circuitry. --Rick Sidwell 03:20, 8 Jun 2005 (UTC)

~~ @Rick Sidwell "they subtract using subtraction circuitry" ~~ A subtraction is performed by inverting the B inputs (making one's complement) before they reach the adder. In the adder the carry will add 1 (in effect turning the one's complement into two's complement for free. Thank you, carry). If there's was a borrow the carry would have been cleared at an earlier stage, in which case the addition of 1 would have been omitted. Neat, isn't it? :-) Maybe modern processors have added circuitry that's dedicated to subtraction, I don't know, but this is the way it was always done. SvenPB 14:14, 15 August 2005 (UTC)[reply]

Makes sense. I've been meaning to rework this article for awhile, and included this in the new version. Please correct it if I got it wrong! It certainly still needs some work; I'd like to include a discussion of how mechanical calculators like the Pascaline and Curta made use of the method of complements. --Rick Sidwell 02:09, 18 August 2005 (UTC)[reply]
When building an adder, it is not a lot of work to add the XOR gates to invert one input. Also, since there is usually a carry-in line, one uses that for the add one, so it is then a two's complement subtractor. Note, though, that as noted above, in the case of ones complement it is somewhat usual to use subtract logic. If you use subtract logic, then as long as neither input is -0, the output won't be -0. Then you complement the second operand and you have an adder, again with no -0 as long as neither operand is -0. Make people happy not seeing -0 when not expected. Gah4 (talk) 05:47, 28 October 2023 (UTC)[reply]

Deletion[edit]

I removed the following incorrect text:

The n's complement of m is n - m. For example, the ten's complement of 7 is 3; the one's complement of 1/3 is 2/3, the hundred's complement of 28 is 72.

It's true that the ten's complement of 7 is 3, and if you consider "28" a single digit in base 100, I suppose it's hundred's complement is "72". But the ten's complement of 28 is also 72, not -62, and the ten's complement of 007 is 993. And ones complement (no matter where you put the apostrophe) only makes sense in base 2; the example would be something like the ones' complement of 01/11 is 10/11, which may look like 1/3 and 2/3 converted to binary until you add more digits and get 0001/0011 and 1110/0011. --Rick Sidwell 00:41, 14 September 2005 (UTC)[reply]

What is going on here is that the same word, "complement", is used in two very different contexts, computer science and elementary education. I'll move the way the word is used in elementary education to the proper section. Maybe we should split the article, and expand the education section with more examples of how complements are being used to teach subtraction. Rick Norwood 12:28, 14 September 2005 (UTC)[reply]

Borrowing complex[edit]

How exactly is borrowing any more complex than carrying (which you have to do in this method)? Plugwash

I can only say that schoolchildren find it so, especially when you have to borrow from a number several columns to the left. Apparently computers also find carrying easier than borrowing. Rick Norwood 20:49, 24 September 2005 (UTC)[reply]
I think i've realised why humans find borrowing tricky, its because adding two single digit numbers to produce a small two digit number is drummed into thier heads. whereas subtracting two single digit numbers in the same way isn't (negative numbers are normally done as sign-magnitute and aren't taught until later).
As for computers they do it that way because it allows them to have one set of cuircitry for addition and subtraction and it probablly seemed saner to do subtraction by additions and complements than addition by subtraction and complements. Plugwash 21:21, 24 September 2005 (UTC)[reply]
I would like some sources to back up the statement schoolchildren find it so. It's not that I don't believe it, but it would be good to have a justification. 171.16.2.2 13:41, 28 October 2005 (UTC)[reply]
Sources would be nice, although I personally don't know where to look for them. But to answer the original question, borrowing is more complex than carrying in several ways. With carrying, you generate the carry after adding the digits in one column and immediately use it by adding it to the next column. With borrowing, you borrow before subtracting, and the common practice is to cross out the digit and write one less above it, with the special consideration when the digit is zero to write nine and repeat the borrowing process. A simpler way would be to just mark that 1 was borrowed and deal with it when subtracting that column and marking a borrow from the next column if it is needed (including the case when the digit is zero). That's how an electronic "full subtracter" would work, but it isn't very intuitive for a human doing a manual subtraction. --Rick Sidwell 21:56, 29 October 2005 (UTC)[reply]
For humans, and I suppose for other than binary computers, borrow might be more complicated. But in binary computers, borrow is exactly the opposite of carry. This is more obvious with computers that have "add with carry" and "subtract with borrow" instructions. Some reverse the logic for borrow, others don't. As for schoolchildren, I suspect that they have more practice with carry, so it seems easier. Gah4 (talk) 19:56, 9 September 2020 (UTC)[reply]

End around carry in nines compliment[edit]

The article says "Fortunately, a trick can be used to get around this addition: Instead of always setting a carry into the least significant digit when subtracting, the carry out of the most significant digit is used as the carry input into the least significant digit (an operation called an end-around carry). So if y ≤ x, the carry from the most significant digit that would normally be ignored is added, producing the correct result. And if not, the 1 is not added and the result is one less than the radix complement of the answer, or the diminished radix complement, which does not require an addition to obtain."

I wish the author of this section could provide a numerical example. I am trying see this and how it works on pencil and paper, but somehow I am missing the method. Thanks. 192.80.95.242 (talk) 14:48, 12 June 2008 (UTC) —Preceding unsigned comment added by 192.80.95.242 (talk) 14:45, 12 June 2008 (UTC)[reply]

Yes this is the common way, at least for binary. A two's complement subtractor inverts the input bits and uses a carry-in of 1, ignoring overflow. A ones' complement subtractor compliments the bits, and uses the carry-out as the carry-in. That should work for nines' complement in the same way. Gah4 (talk) 20:04, 9 September 2020 (UTC)[reply]

Proof Required[edit]

The article says, any number less than b/2 will be positive, so 0,1,2,3,4 will be positive & other's negative. But is there any proof for above statement. Also, I was doing following calculation - 1 - 999,

999, 10's complement will be 001, adding it to 1, makes it 002. Now the statment says, 0 should be positive, so the answer should be +002, which is wrong. Please let me know, in which step i did wrong calculation or assumption. Tushar39 (talk) 09:46, 31 October 2009 (UTC)[reply]


>The subtle difference in apostrophe placement is not common practice. Not to mention inaudible. 87.213.97.66 (talk) 12:01, 20 April 2011 (UTC)[reply]

Only half the number can be used, so 1 to 499 are positive, and 500 to 999 are negative. 999 is the representation of -1 or -2. Gah4 (talk) 20:06, 9 September 2020 (UTC)[reply]

Subtraction in paragraph "Negative number representations"[edit]

In order for the subtraction result to be -144 (which is right), the "+1" is not right because "856 happens to be the ten's complement of 144" isn't either. So why is it there? No explanation for the addition of 1 either. — Preceding unsigned comment added by 94.69.24.164 (talk) 16:14, 25 May 2012 (UTC)[reply]

Yes, this is confusing. It should explain either nines' complement or ten's complement, and say which one it is doing. Gah4 (talk) 20:42, 9 September 2020 (UTC)[reply]

zero[edit]

The article never explains zero, and specifically negative zero. There are two solutions computers use for negative zero. One is to always compare equal to positive zero, and the other is not to generate one, given no inputs are negative zero. The latter case is easily done by building the logic of a ones' complement subtractor, and do addition by adding the complement. The article might mention this. Gah4 (talk) 20:45, 9 September 2020 (UTC)[reply]

ten's complement[edit]

The article mentions decimal, and then all the examples are nines' complement. Can we have a ten's complement example? I wanted to link to this one. Gah4 (talk) 05:50, 28 October 2023 (UTC)[reply]