🌐
Cornell University
cs.cornell.edu › ~tomf › notes › cps104 › twoscomp.html
Two's Complement
Suppose we're working with 8 bit ... digits. 0 becomes 1, 1 becomes 0. ... Then we add 1. ... That is how one would write -28 in 8 bit binary. Use the number 0xFFFFFFFF as an example....
operation on binary numbers, and number representation based on this operation
Two's complement is the most common method of representing signed (positive, negative, and zero) integers on computers, and more generally, fixed point binary values. As with the ones' complement and sign-magnitude systems, … Wikipedia
🌐
Wikipedia
en.wikipedia.org › wiki › Two's_complement
Two's complement - Wikipedia
3 weeks ago - The defining property of being ... using binary with numbers up to three bits (so N = 3 and 2N = 23 = 8 = 10002, where '2' indicates a binary representation), a two's complement for the number 3 (0112) is 5 (1012), because summed to the original it gives 23 = 10002 = 0112 ...
Discussions

I'm having trouble understanding 'two's compliment', can someone explain this to me please?!
It is a useful convention. The same circuits and logic operations that add / subtract positive numbers in binary still work on both positive and negative numbers if using the convention, that's why it's so useful and omnipresent. Imagine the odometer of a car, it rolls around at (say) 99999. If you increment 00000 you get 00001. If you decrement 00000, you get 99999 (due to the roll-around). If you add one back to 99999 it goes back to 00000. So it's useful to decide that 99999 represents -1. Likewise, it is very useful to decide that 99998 represents -2, and so on. You have to stop somewhere, and also by convention, the top half of the numbers are deemed to be negative (50000-99999), and the bottom half positive just stand for themselves (00000-49999). As a result, the top digit being 5-9 means the represented number is negative, and it being 0-4 means the represented is positive - exactly the same as the top bit representing sign in a two's complement binary number. Understanding this was hard for me too. Once I got it and went back to re-read the books articles and explanations (there was no internet back then), it turned out a lot of those describing it didn't really understand it. I did write a book teaching assembly language after that (which did sell quite well for 10 years). More on reddit.com
🌐 r/compsci
45
60
May 26, 2014
binary - What is “two's complement”? - Stack Overflow
I'll use 8 digits ("bits") for these examples. So our binary number would really be 00001111 or 0 × 27 + 0 × 26 + 0 × 25 + 0 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 1 × 20 · To form the 2's complement negative, we first complement all the (binary) digits to form 11110000 and add 1 to form ... More on stackoverflow.com
🌐 stackoverflow.com
Confused about one's complement and two's complement
I have no idea why they teach one’s complement. Some ancient computers used it to represent negative numbers. Two’s complement is the normal way of representing negative numbers, because then you can add them in the normal way. In software, it can come up during debugging if you’re looking at hex or binary representations, low-level programming, or dealing with overflow. More on reddit.com
🌐 r/learnmath
3
2
October 19, 2023
ELI5 1s compliment and 2s compliment

Ones complement is basically the fact that a negative number is represented by flipping the bits of the positive representation. Say you have a 4 bit number with the first bit representing the sign, then +1 would be 0001 and -1 would be 1110.

Ones complement is not the ideal way to represent a signed number because you could have 0 represented as 0000 and 1111 (the signed version). It doesn't make any sense to have 2 representations of 0 and is a waste (you have 1 less number represented than you could possibly have).

Twos compliment alleviates this issue by 'flipping the bits and adding one'. So 0001 (1) would be 1110 + 1 = 1111 (-1).

And 0000 (0) would be 1111 + 1 = 0000 (ie only one representation for 0 in 4 bits)

To get a twos complement number's value, just follow the same operation of flipping and adding. 1111 would be 0000 + 1 = 0001 = 1. Hence 1111 represents -1.

Now, with that said, what number does 1000 represent if you are using ones complement? Now twos complement?

1000 is signed, so it represents a negative number.. but if you flip and add you get 0111 + 1 = 1000.. which is the same number. Well not quite. What it is telling you is the VALUE of the number. 1000 is 8. Hence 1000 (signed) is -8. Because you dont have a negative 0, you can represent one more value in the negative range than in positive. So a 4 bit signed integer can represent -8 to 7. An unsigned 4 bit int can represent 0 to 15. Both can represent 16 numbers.

More on reddit.com
🌐 r/csELI5
10
13
February 4, 2014
🌐
Built In
builtin.com › articles › twos-complement
Two’s Complement: A Guide | Built In
With two’s complement, when the ... the number is signed as positive. For example, two’s complement of 4 in binary (0100) becomes 1100 to represent -4....
🌐
RIT
rit.edu › academicsuccesscenter › sites › rit.edu.academicsuccesscenter › files › documents › math-handouts › DM3_TwosComplement_BP_9_22_14.pdf pdf
Two's Complement
Step 3: Add 1 to your result. This is the two’s complement representation of the negative ... Add 1: 1110 1110 + 1 = 1110 1111. Thus the two’s complement for -17 is 1110 11112. It begins on the left with a 1, therefore we ... EXAMPLE 1: Subtract 17 from 23, as a computer would, using binary ...
🌐
GeeksforGeeks
geeksforgeeks.org › digital logic › twos-complement
Two's Complement - GeeksforGeeks
3 weeks ago - 2’s complement is obtained by removing -0 from the 1’s complement table and shifting negative values one step down.
🌐
Oxford University
mathcenter.oxford.emory.edu › site › cs170 › twosComplement
The Two's Complement
Amazingly, representing negative numbers in this way allows us to compute the sum of two numbers, regardless of their signs, in the SAME way -- via normal binary addition! 5 00000101 +3 00000011 ---- ---------- 8 00001000 (which represents 8) 5 00000101 +(-3) 11111101 ------- ---------- 2 00000010 ...
🌐
TutorialsPoint
tutorialspoint.com › two-s-complement
Two's Complement\\n
November 8, 2023 - Generally, there are two types of complement of Binary number: 1’s complement and 2’s complement. To get 1’s complement of a binary number, simply invert the given number. For example, 1’s complement of binary number 110010 is 001101. To get 2’s complement of binary number is 1’s complement of given number plus 1 to the least significant bit (LSB).
Find elsewhere
🌐
All About Circuits
allaboutcircuits.com › home › technical articles › two’s complement representation: theory and examples
Two’s Complement Representation: Theory and Examples - Technical Articles
November 17, 2017 - However, if we assume these four-bit numbers as signed values, then, we will obtain the signed decimal values inside the circle. For example, $$1101_{(2)}$$ is a negative number since sign bit is one. Using the third column of the above table or, equivalently, calculating its two’s complement, we see that $$101_{(2)}$$ corresponds to decimal $$3$$, hence, $$1101_{(2)}=-3_{(10)}$$.
🌐
Google
sites.google.com › rgc.aberdeen.sch.uk › rgc-highercomputing › computer-systems › data-representation › twos-complement
Higher Computing Science Revision - Two's Complement
If we look at an 8 bit two’s complement number such as 1111 0111 (-9) You should notice that the right hand bit is (-27) which is (-2n-1) where n is the number of bits.
🌐
Emory
cs.emory.edu › ~cheung › Courses › 255 › Syllabus › 5-repr › 2s-comp.html
2s complement codes
Values 8 digit 2's compl repr Subtract 2 positive 5 00000101 values - 9 - 00001001 ----- ---------- -4 11111100 -> represents -4 Subtract positive - 5 00000101 negative - -9 - 11110111 ----- ---------- 14 00001110 -> represents 14 Subtract negative - -5 11111011 positive - 9 - 00001001 ----- ---------- -14 11110010 -> represents -14 Subtract 2 negative -5 11111011 values - -9 - 11110111 ----- ---------- 4 00000100 -> represents 4 · Example Program: (Demo above code) &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › 1s-2s-complement-binary-number
1's and 2's complement of a Binary Number - GeeksforGeeks
March 20, 2025 - The idea is to first compute the 1's complement by flipping each bit of the binary string. Then, to find the 2's complement, we add 1 to the 1's complement, starting from the rightmost bit. If all bits are flipped, an extra '1' is added at the beginning.
🌐
VEDANTU
vedantu.com › maths › 2s complement addition explained: concepts & practice
2S Complement Addition: Step-by-Step Guide with Examples
For example, let's convert 122 to binary form. We start by dividing the number, 122 by 2, as shown in the table, and noting the remainder in reverse order, i.e. 111010. Thus the binary representation of 122 is 111010.
🌐
QBasic on Your Computer
chortle.ccsu.edu › assemblytutorial › Chapter-08 › ass08_19.html
Two's Complement Integers
What integers can be represented in 8-bit two's complement? Two's complement represents both positive and negative integers. So one way to answer this question is to start with zero, check that it can be represented, then check one, then check minus one, then check two, then check minus two ...
🌐
Mc
sandbox.mc.edu › ~bennet › cs110 › tc › add.html
Two's Complement Binary Addition Examples
[Decimal to Two's Complement Conversion] [Two's Complement to Decimal Conversion] [Two's Complement Binary Addition Examples] Here are some examples of eight-bit, twos complement binary addition. In each case, we compute the sum, and note if there was an overflow.
Top answer
1 of 5
139
It is a useful convention. The same circuits and logic operations that add / subtract positive numbers in binary still work on both positive and negative numbers if using the convention, that's why it's so useful and omnipresent. Imagine the odometer of a car, it rolls around at (say) 99999. If you increment 00000 you get 00001. If you decrement 00000, you get 99999 (due to the roll-around). If you add one back to 99999 it goes back to 00000. So it's useful to decide that 99999 represents -1. Likewise, it is very useful to decide that 99998 represents -2, and so on. You have to stop somewhere, and also by convention, the top half of the numbers are deemed to be negative (50000-99999), and the bottom half positive just stand for themselves (00000-49999). As a result, the top digit being 5-9 means the represented number is negative, and it being 0-4 means the represented is positive - exactly the same as the top bit representing sign in a two's complement binary number. Understanding this was hard for me too. Once I got it and went back to re-read the books articles and explanations (there was no internet back then), it turned out a lot of those describing it didn't really understand it. I did write a book teaching assembly language after that (which did sell quite well for 10 years).
2 of 5
23
A minor typo, but I've seen it in replies as well as the post: *complement (in this case, the name comes from complementing all the bits to nearly-negate a number.)
🌐
Baeldung
baeldung.com › home › core concepts › two’s complement
Two's Complement | Baeldung on Computer Science
March 18, 2024 - In binary, or base 2, each placeholder is a multiple of 2. So, the same equation in binary would be: Note again that we still need to carry, and computers come with special circuitry to handle that case.
🌐
ScienceDirect
sciencedirect.com › topics › computer-science › twos-complement-number
Two's Complement Number - an overview | ScienceDirect Topics
Examples of arithmetic operations include: subtracting 3 (0011₂) from 5 (0101₂) by taking the two's complement of 3 to get 1101₂, then adding 0101₂ + 1101₂ = 0010₂, which is 2 in decimal. Subtracting 5 (0101₂) from 3 (0011₂) by taking the two's complement of 5 to get 1011₂, ...
Top answer
1 of 16
740

Two's complement is a clever way of storing integers so that common math problems are very simple to implement.

To understand, you have to think of the numbers in binary.

It basically says,

  • for zero, use all 0's.
  • for positive integers, start counting up, with a maximum of 2(number of bits - 1)-1.
  • for negative integers, do exactly the same thing, but switch the role of 0's and 1's and count down (so instead of starting with 0000, start with 1111 - that's the "complement" part).

Let's try it with a mini-byte of 4 bits (we'll call it a nibble - 1/2 a byte).

  • 0000 - zero
  • 0001 - one
  • 0010 - two
  • 0011 - three
  • 0100 to 0111 - four to seven

That's as far as we can go in positives. 23-1 = 7.

For negatives:

  • 1111 - negative one
  • 1110 - negative two
  • 1101 - negative three
  • 1100 to 1000 - negative four to negative eight

Note that you get one extra value for negatives (1000 = -8) that you don't for positives. This is because 0000 is used for zero. This can be considered as Number Line of computers.

Distinguishing between positive and negative numbers

Doing this, the first bit gets the role of the "sign" bit, as it can be used to distinguish between nonnegative and negative decimal values. If the most significant bit is 1, then the binary can be said to be negative, where as if the most significant bit (the leftmost) is 0, you can say the decimal value is nonnegative.

"Sign-magnitude" negative numbers just have the sign bit flipped of their positive counterparts, but this approach has to deal with interpreting 1000 (one 1 followed by all 0s) as "negative zero" which is confusing.

"Ones' complement" negative numbers are just the bit-complement of their positive counterparts, which also leads to a confusing "negative zero" with 1111 (all ones).

You will likely not have to deal with Ones' Complement or Sign-Magnitude integer representations unless you are working very close to the hardware.

2 of 16
397

I wonder if it could be explained any better than the Wikipedia article.

The basic problem that you are trying to solve with two's complement representation is the problem of storing negative integers.

First, consider an unsigned integer stored in 4 bits. You can have the following

0000 = 0
0001 = 1
0010 = 2
...
1111 = 15

These are unsigned because there is no indication of whether they are negative or positive.

Sign Magnitude and Excess Notation

To store negative numbers you can try a number of things. First, you can use sign magnitude notation which assigns the first bit as a sign bit to represent +/- and the remaining bits to represent the magnitude. So using 4 bits again and assuming that 1 means - and 0 means + then you have

0000 = +0
0001 = +1
0010 = +2
...
1000 = -0
1001 = -1
1111 = -7

So, you see the problem there? We have positive and negative 0. The bigger problem is adding and subtracting binary numbers. The circuits to add and subtract using sign magnitude will be very complex.

What is

0010
1001 +
----

?

Another system is excess notation. You can store negative numbers, you get rid of the two zeros problem but addition and subtraction remains difficult.

So along comes two's complement. Now you can store positive and negative integers and perform arithmetic with relative ease. There are a number of methods to convert a number into two's complement. Here's one.

Convert Decimal to Two's Complement

  1. Convert the number to binary (ignore the sign for now) e.g. 5 is 0101 and -5 is 0101

  2. If the number is a positive number then you are done. e.g. 5 is 0101 in binary using two's complement notation.

  3. If the number is negative then

    3.1 find the complement (invert 0's and 1's) e.g. -5 is 0101 so finding the complement is 1010

    3.2 Add 1 to the complement 1010 + 1 = 1011. Therefore, -5 in two's complement is 1011.

So, what if you wanted to do 2 + (-3) in binary? 2 + (-3) is -1. What would you have to do if you were using sign magnitude to add these numbers? 0010 + 1101 = ?

Using two's complement consider how easy it would be.

 2  =  0010
 -3 =  1101 +
 -------------
 -1 =  1111

Converting Two's Complement to Decimal

Converting 1111 to decimal:

  1. The number starts with 1, so it's negative, so we find the complement of 1111, which is 0000.

  2. Add 1 to 0000, and we obtain 0001.

  3. Convert 0001 to decimal, which is 1.

  4. Apply the sign = -1.

Tada!

🌐
AllMath
allmath.com › twos-complement.php
Two's (2's) Complement Calculator
Find the 2s complement of (50)10. ... Step 1: Convert the given decimal number to binary. ... Step 2: Take one’s complement of the binary number by converting each 0 to 1 and 1 to 0.
🌐
VEDANTU
vedantu.com › maths › 2's complement subtraction made easy
2's Complement Subtraction: Step-by-Step Guide with Examples
Step 4: To get an answer in true form, take 2’s complement and change its sign. Example: Subtract $(1010)_2$ from $(1000)_2$ using 2's complement.