Talk:Two's complement

message: This page covers addition, subtraction and multiplication. But what about division? (restoring/non-restoring) —Preceding unsigned comment added by 128.54.69.212 (talk • contribs) 18:50, 7 February 2007
:It's in the to-do list.  Have at it. Dicklyon 01:08, 8 February 2007 (UTC)
replies: text: More specifically, the sign of the remainder depends on which way you do it. Gah4 (talk) 20:03, 15 February 2017 (UTC)
thread_title:  Division 

message: The weight of the least significant bit (LSB) is often assumed in this article to be 1, which is not a problem for addition or subtraction, and multiplication.  However, the value 0111 in a two's compliment system can represent 7, 7/8, 7/4, for LSB weights of 1, 1/8th, and 1/4 respectively.  This *usually* does not matter for many operators; however, it does in fact matter for some operators.  E.g, the square root operator used on 0100 would produce 0010 if the weight of the LSB is 1, but would produce approimately 0101 (trucation) or 0110 (rounding) if the weight of the LSB is 1/8. Tata2007 18:11, 3 October 2007 (UTC)
replies: text: It is always much easier to discuss the two's-complement representation of integers, but you're right that a note somewhere about how fixed-point fractions and floating-point mantissas use these integers with a power-of-two multiplier, whether implicit or explicit. Dicklyon 21:11, 3 October 2007 (UTC)
replies: text: While many people understand decimal fractions, not so many such fractions in other radices. As with decimal, it can be generalized once the integer representation is understood.  There could be a whole article on scaled binary (and other radix) arithmetic.  PL/I is one of the few languages that can do this. Gah4 (talk) 21:32, 14 September 2018 (UTC)
replies: text: Recent edits remind me of this. I believe that the IBM descriptions for S/360 and successors don't restrict them to integers, but generically fixed point values, where one must keep track of the radix point.  Note that most processors generate a double length product, and accept a double length dividend, both necessary when the radix point isn't immediately to the right of the LSD. Few computer languages (PL/I being one that I have used) directly support fixed point with a moved radix point.  (PL/I allows it to move either direction.)   Since INTEGER in Fortran, and later int in C, have reinforced this distinction, it is not commonly taught.  It might be that this article would be a good place to do it. Gah4 (talk) 23:27, 2 March 2019 (UTC)

text: I agree that this article should mention fixed-point fractions, but perhaps the fixed-point arithmetic article is a better place for the details. --DavidCary (talk) 08:29, 3 March 2022 (UTC)
thread_title:  Weighting of LSB is assumed to be 1 for this article. 

message: I wonder if it might be useful to explain 2's complement of fractional numbers like 1.5 or -1.5.
I'm an elecrical engineering student, and the computer science professors want us to know how to represent a number like -6.5625 in 2's complement. I wasn't able to find an explanation anywhere on the web. The explanation should be easy as the digit to have 1 added to it is still the LSB (as opposed to the '1's' digit). 
Another thought would be a clarification that there are no 'negative binary numbers' until a coding scheme is used to encode them.
71.139.179.199 (talk) 01:59, 6 February 2013 (UTC)
thread_title:  Fractional 2's complement? 

message: 2's complement of a N-bit number (sign bit included) can be calculated by 1's complement + 1 (LSB), but that is not the same as the N-bit number subtracted from 2^N, as stated in the original article.
It is the same as the N-bit number subtracted from 2^(N+1) or from 0 (zero), with the most significant bit (MSB) ignored after the subtraction in both cases. 
The reason is that the original N-bit number plus its negative, must equal zero.  137.158.153.203 (talk) 10:53, 19 February 2013 (UTC)
replies: text: Yes, the current formulation is not tidy enough. It would be correct to say: two's complement of a positive number  is the same bit vector as unsigned binary of . Objections against this rewording? Incnis Mrsi (talk) 11:32, 19 February 2013 (UTC)

text: The problem exists, although possibly not the same that the IP said (and thought) about.  may not be posed as a definition or an unconditional rule for computing , since it only makes sense for positive  (unless we consider all things modulo , in which case the  additive term can be omitted and the formula looks tautological). Incnis Mrsi (talk) 18:18, 19 February 2013 (UTC)
thread_title:  Not the complement of 2^N 

message: In the first part of the article, the formula   to   is given to get the highest and lowest number in a two's complement system.
The problem is, this is only true if you use a binary system.
The article is about binary systems, but shouldn't it be changed?
You can use it with a decimal system and any system with a different radix as well.
The formula would change from  
 to   to 
 to  
Where R is the radix of the system and N the amount of digits.
— Preceding unsigned comment added by 89.98.82.197 (talk) 17:55, 11 September 2013
: The two's complement by definition is used only for binary numbers (since the term is derived from ones' complement), and only for integers. Certainly you can generalize it for other positional numeral systems, you can do it in several ways, and not necessarily for even radices. But is any of such generalizations mentioned in WP:reliable sources? Incnis Mrsi (talk) 12:26, 12 September 2013 (UTC)
replies: text: The more general names, I believe from Knuth, are digit complement and radix complement. That said, the radix complement system for base three should be called twos' complement, (if I understand, again, the Knuth notation regarding the apostrophe). In decimal, you have 10's complement and nines' complement. Gah4 (talk) 19:28, 26 August 2015 (UTC)

text: I agree that Wikipedia should describe ten's complement, nines' complement, and other generalized systems. But rather than put every detail in this two's complement article, wouldn't it be better to put those details about non-binary systems in the general method of complements article? --DavidCary (talk) 15:30, 25 February 2016 (UTC)
thread_title:  Range of the two's complement system. 

message: The article suggests the following.
# 1001, 11001, 111001 are two's complement representations of negative seven. [a]
# 0111, 00111, 000111 are two's complement representations of seven. [b]
# 1001, 11001, 111001 are two's complements of seven. [c]
# 0111, 00111, 000111 are two's complements of negative seven. [c]
Statements 2 and 3 seem awkwardly at odds. Likewise for statements 1 and 4.
Rather than using headings "converting from..." and "converting to..." it might be helpful to expand the headings to say "converting from x to y". Then provide algorithms that take an x as input and produce a y as output. One does not convert a number to some representation. Rather, one converts a representation of a number into another representation of that same number. I imagine language like, "To convert a number in notation A into notation B use operation C."
[a] from Converting to two's complement representation: "negative numbers are represented by the two's complement of the absolute value"
[b] from Converting to two's complement representation: "In two's complement notation, a non-negative number is represented by its ordinary binary representation"
[c] from From the ones' complement: "To get the two's complement of a binary number, the bits are inverted...the value of 1 is then added"
IOLJeff (talk) 20:33, 30 May 2015 (UTC)
thread_title:  notation versus operation 

message: A recent edit has the summary misleading and incorrect.  I suppose it is a little misleading, but not so incorrect.  But now I see: The two's complement of a number behaves like the negative of the original number in most arithmetic, This leaves the question of what most arithmetic is?  Two's complement doesn't behave like the negative in decimal arithmetic, which many people might consider most.  There is ten's complement for that, but maybe not an article on  it.  Is most here misleading and/or incorrect? Gah4 (talk) 19:56, 15 February 2017 (UTC)
thread_title:  most arithmetic 

message: 2: hey 1 ur really cool
1: thx  — Preceding unsigned comment added by 100.6.110.197 (talk) 11:06, 27 May 2017 (UTC)
thread_title:  idk 

message: You made some changes to my recent revision to this page, accompanied by the following note:
I see now that the tables, as I rewrote them, were not as clear as I had intended. The columns represent: a binary (two's-complement) representation of a number, the corresponding decimal number, and its two's complement. I labeled the first column "binary" in the interest of brevity and on the assumption that "two's-complement notation" would be safely implied, but in retrospect, it opened the table to misinterpretation. 
To be clear, the instructive purpose of the table is for readers to be able to connect the right- and left-hand values of a given decimal number and its negation (e.g., 010 represents 2 which has two's complement 110 which represents -2 which has two's complement 010). As you've edited them, the lefthand columns are identical to the righthand columns, except that they are blank for negative values. The instructive purpose of this presentation is not clear to me.
I have reverted the changes and reorganized and relabelled the table. What are your thoughts?
—Pennbrook (talk) 06:24, 6 December 2017 (UTC)
thread_title:  Recent changes to the introductory table 

message: From the ones' complement
To get the two's complement of a binary number, the bits are inverted, or "flipped", by using the bitwise NOT operation; the value of 1 is then added to the resulting value, ignoring the overflow which occurs when taking the two's complement of 0.
For example, using 1 byte, the decimal number 5 is represented by
0000 01012
The most significant bit is 0, so the pattern represents a non-negative value. To convert to −5 in two's-complement notation, the bits are inverted; 0 becomes 1, and 1 becomes 0:
1111 10102
At this point, the numeral is the ones' complement of the decimal value −5. To obtain the two's complement, 1 is added to the result, giving:
1111 10112
Dotarpa (talk) 23:05, 7 April 2018 (UTC)
replies: text: Yes, it is confusing. The subsection is supposed to describe converting ones' complement to two's complement representation. It actually described converting +5 (in any binary representation) to -5 in two's complement. But also, as you are noticing, has the ambiguity described in the article: that the terms ones' complement and two's complement apply to both the representation, and to the negation operation. You have to figure out from context which one is meant. Gah4 (talk) 00:06, 8 April 2018 (UTC)
replies: text: It's not as simple as changing the sentence to read "At this point, the numeral is the ones' complement with the decimal value −5"??  Perhaps it is just going over my head.  Is not "1111 1010" the ones' complement of +5?  Dotarpa (talk) 16:21, 8 April 2018 (UTC)
replies: text:  1111 1010, representing -5 in ones complement representation, is the ones' complement of 0000 0101, representing +5. Gah4 (talk) 18:46, 8 April 2018 (UTC)
thread_title:  At this point, the numeral is the ones' complement of the decimal value −5.  < < Should this be a positive 5?? 

message: I get confused over converting outputs in linux... there is no binary dump and the hexdump and hd or od octal dumps act strange by swapping nibbles of data for big endian vs little endian. So most code I read seems to limit transmission of data to 1 character at a time instead of in words to avoid this problem.
In octal I am especially confused because the bits will not align unless 3 bytes (or a multiple of 3 bytes) are used; every 2 octals is only 6 bits leaving 2 bits unused from a byte. So to use up every bit the number bits needs to be divisible by 3. This occurs at 24 bits which is every 3 bytes. Every Octal is three bits. I am confused about the end of string marker \0 is this octal zero which is 3 bits or is this two ASCII chars which is 2 bytes. Also would \0x1b be equal to \033 Is there the leading zero padding??  — Preceding unsigned comment added by 2600:6C51:7001:200:9856:7AA4:80B6:A255 (talk) 00:13, 10 September 2019 (UTC)
thread_title:   Add a section on Computational effects of Big Endian vs Little Endian or Middle Endian ie melong types 

message: The current intro text says
: The two's complement of an -bit number is defined as its complement with respect to . For instance, for the three-bit number 010, the two's complement is 110, because . The two's complement is calculated by inverting the digits and adding one.
This sounds a bit odd since the table lists the two's complement of 000 as 000, and by the same pattern we would have . Clearly wrong, so what is the best way to rephrase this? Does the true definition of two's complement include an expanded bit range in the output (so that the table is wrong, and the two's complement of 000 is actually 1000), or ...? --Nanite (talk) 17:13, 1 December 2019 (UTC)
thread_title:  000 + 000 = 1000 ? 

message: Saw this figure on TeXample.net:
https://texample.net/tikz/examples/complement/
I'm not sure what the caption would be, or where it would fit in the article. But if someone who knows more about this subject can add it, I think it's under a Creative Commons license with attribution.  — Preceding unsigned comment added by 2601:1C2:680:DDE0:C904:B420:F87B:3F4E (talk) 18:30, 25 January 2021 (UTC)
thread_title:  Possible diagram 

message: Right now, the definition of two's complement is
> Two's complement is a mathematical operation to reversibly convert a positive binary number into a negative binary number with equivalent (but negative) value, using the binary digit with the greatest place value (the leftmost bit in big-endian numbers, rightmost bit in little-endian numbers) to indicate whether the binary number is positive or negative (the sign).
But I don't think it is an "operation".  Maybe "converting to two's complement" is an operation, but two's complement is official a representation method, or representation of positive and negative numbers using binary digits.  — Preceding unsigned comment added by Winterheat (talk • contribs) 16:18, 13 August 2022 (UTC)
replies: text: You can "two's complement" a number by flipping all the bits and adding 1, which negates a number that's in two's complement representation.  Ones' complement is also written with the first paragraph talking about the operation of "ones' complementing" a number, but it also talks about "ones' complement arithmetic" and "ones' complement binary". This article, however, doesn't, but it probably should. Guy Harris (talk) 19:39, 13 August 2022 (UTC)
thread_title:  The definition of two's complement 

message: I put a  on the explanation for the name, and especially never heard it before. When I learned it when I was about 10, it was that two's complement is one more than one's complement.  (The way they spelled it 55 years ago.) I never searched for an explanation of the name before, but it should trace back close to when the name was first used.Gah4 (talk) 02:15, 10 May 2023 (UTC)
thread_title:  origin of the name