ArticleslgStudy

science

Two's complement

Two's complement is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Two's complement rather than just read about it. In short: 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, two's complement uses the most significant bit as the sign to indicate positive (0) or negative (1) numbers, and nonnegative numbers are given their unsigned representation (6 is 0110, zero is 00…

Two's complement — main illustration
Two's complement — illustration

Key takeaways

  • Two's complement belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Two's complement to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Two's complement from memory before moving on to harder problems.

Reference excerpt

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, two's complement uses the most significant bit as the sign to indicate positive (0) or negative (1) numbers, and nonnegative numbers are given their unsigned representation (6 is 0110, zero is 0000); however, in two's complement, negative numbers are represented by taking the bit complement of their magnitude and then adding one (−6 is 1010). The number of bits in the representation may be increased by padding all additional high bits of negative or positive numbers with 1's or 0's, respectively, or decreased by removing additional leading 1's or 0's. Unlike the ones' complement scheme, the two's complement scheme has only one representation for zero, with room for one extra negative number (the range of a 4-bit number is −8 to +7). Furthermore, the same arithmetic implementations can be used on signed as well as unsigned integers and differ only in the integer overflow situations, since the sum of representations of a positive number and its negative is 0 (with the carry bit set).

Procedure The following is the procedure for obtaining the two's complement representation of a given negative number in binary digits:

Step 1: starting with the absolute binary representation of the number, with the leading bit being a sign bit; Step 2: inverting (or flipping) all bits – changing every 0 to 1, and every 1 to 0; Step 3: adding 1 to the entire inverted number, ignoring any overflow. Accounting for overflow will produce the wrong value for the result. For example, to calculate the decimal number −6 in binary from the number 6:

Step 1: +6 in decimal is 0110 in binary; the leftmost significant bit (the first 0) is the sign (just 110 in binary would be −2 in decimal). Step 2: flip all bits in 0110, giving 1001. Step 3: add the place value 1 to the flipped number 1001, giving 1010. To verify that 1010 indeed has a value of −6, add the place values together, but subtract the sign value from the final calculation. Because the most significant value is the sign value, it must be subtracted to produce the correct result: 1010 = −(1×23) + (0×22) + (1×21) + (0×20) = 1×−8 + 0 + 1×2 + 0 = −6.

Steps 2 and 3 together are a valid method to compute the additive inverse − n {\displaystyle -n} of any (positive or negative) integer n {\displaystyle n} where both input and output are in two's complement. An alternative to compute − n {\displaystyle -n} is to use subtraction 0 − n {\displaystyle 0-n} . See below for subtraction of integers in two's complement.

Theory

Two's complement is an example of a radix complement. The 'two' in the name refers to the number 2N - "two to the power of N", which is the value in respect to which the complement is calculated in an N-bit system (the only case where exactly 'two' would be produced in this term is N = 1, so for a 1-bit system, but these do not have capacity for both a sign and a zero). As such, the precise definition of the two's complement of an N-bit number is the complement of that number with respect to 2N. The defining property of being a complement to a number with respect to 2N is simply that the summation of this number with the original produce 2N. For example, 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 + 1012. Where this correspondence is employed for representing negative numbers, it effectively means, using an analogy with decimal digits and a number-space only allowing eight non-negative numbers 0 through 7, dividing the number-space into two sets: the first four of the numbers 0 1 2 3 remain the same, while the remaining four encode negative numbers, maintaining their growing order, so making 4 encode −4, 5 encode −3, 6 encode −2 and 7 encode −1. A binary representation has an additional utility however, because the most significant bit also indicates the group (and the sign): it is 0 for the first group of non-negatives, and 1 for the second group of negatives. The tables at right illustrate this property.

Calculation of the binary two's complement of a positive number essentially means subtracting the number from the 2N. But as can be seen for the three-bit example and the four-bit 10002 (23), the number 2N will not itself be representable in a system limited to N bits, as it is just outside the N bits space (the number is nevertheless the reference point of the "Two's complement" in an N-bit system). Because of this, systems with maximally N-bits must break the subtraction into two operations: first subtract from the maximum number in the N-bit system, that is 2N−1 (this term in binary is actually a simple number consisting of 'all 1s', and a subtraction from it can be done simply by inverting all bits in the number also known as the bitwise NOT operation) and then adding the one. Coincidentally, that intermediate number before adding the one is also used in computer science as another method of signed number representation and is called a ones' complement (named that because summing such a number with the original gives the 'all 1s'). Compared to other systems for representing signed numbers (e.g., ones' complement), the two's complement has the advantage that the fundamental arithmetic operations of addition, subtraction, and multiplication are identical to those for unsigned binary numbers (as long as the inputs are represented in the same number of bits as the output, and any overflow beyond those bits is discarded from the result). This property makes the system simpler to implement, especially for higher-precision arithmetic. Additionally, unlike ones' complement systems, two's complement has no representation for negative zero, and thus does not suffer from its associated difficulties. Otherwise, both schemes have the desired property that the sign of integers can be reversed by taking the complement of its binary representation, but two's complement has an exception – the lowest negative, as can be seen in the tables.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Two's complement

Start with the simplest possible case. Write down what Two's complement claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Two's complement before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Two's complement ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Two's complement

In research
Two's complement appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Two's complement in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Two's complement is common in secondary-school and first-year university syllabi. It links to neighbouring topics Binary arithmetic, so understanding it makes those chapters shorter.
In everyday life
Look for Two's complement outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Two's complement” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Two's complement in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Two's complement means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Two's complement out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Two's complement in simple terms?

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, two's complement uses the most significant bit as the sign to indicate posi…

Why does Two's complement matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Two's complement?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Two's complement.

Tags

  • Binary arithmetic

Keep exploring