Two’s complement — solved exercises with an 8-bit odometer, additions that overflow, a 6-bit panel and a practice quiz (and the 9C I read as 156)

In my first IC1 mock exam there was a part that said “the register holds 9C₁₆, in 8-bit two’s complement”. I converted it to decimal as in the number systems topic, 9 · 16 + 12 = 156, wrote it down calmly and moved on. I didn’t even look at the first bit. 9C₁₆ is 10011100, it starts with 1, and in two’s complement it is −100. The worst part is that 156 does not even fit in 8 signed bits: if I had stopped to think about the range, I would have seen it.

These exercises are designed so that those slips happen here and not in the exam. Review the theory and the guided practice if anything sounds odd; here I no longer give you the calculations until the solutions.

How to use this article

  1. Read the statement of each level and solve it on paper, with all the bits and the row of carries.
  2. Compare with the expected result. If it doesn’t match, open the hint before looking at the solution.
  3. In “What is wrong here?” you have three solutions by other students with one mistake each: find it before reading the explanation.
  4. At the end, the practice quiz marks itself and you can repeat it as many times as you like.

Everything is in two’s complement unless stated otherwise.

Level 1: the 8-bit odometer

We keep the 8-bit trip odometer from the theory, which goes forwards (positives) and in reverse (negatives).

a) Represent in 8-bit two’s complement: −13, −64, +90 and −1. b) The odometer shows these codes. Which number is each one? 11101001, 01011010, 10000001 and 11111110. c) A register holds 9C₁₆ in 8-bit two’s complement. Which number is it? d) What range would the odometer have if it had 5 bits? And 12?

Expected result: a) 11110011, 11000000, 01011010, 11111111 · b) −23, +90, −127, −2 · c) −100 · d) −16 … +15 and −2048 … +2047.

In b) and c), the first thing is the leftmost bit. If it is 1, add up the weights with the first one worth −128.

Level 2: additions that overflow

Do these additions in 8-bit two’s complement. For each one, give the result in binary and in decimal, whether there is an end carry and whether there is overflow.

a) 54 + 73 · b) 54 + 74 · c) (−64) + (−64) · d) (−64) + (−65) · e) 25 − 90

Expected result:

AdditionResultEnd carryOverflow
a) 54 + 7301111111 = +127NoNo
b) 54 + 7410000000NoYes
c) (−64) + (−64)10000000 = −128YesNo
d) (−64) + (−65)01111111YesYes
e) 25 − 9010111111 = −65NoNo

a) and b) are on the edge of the range on purpose: 127 fits and 128 does not. The same with c) and d) at the bottom.

Level 3 (challenge): the 6-bit panel

A cheap bike odometer has a panel of only 6 bits in two’s complement.

a) What range can it show? Represent −27, +19 and −9. b) Work out (−27) + 19 in 6 bits and convert the result to 8 bits for the workshop computer. c) Work out (−27) + (−9) in 6 bits. Is there overflow? Check it both ways: by the sign and by the carries of the sign column.

Expected result: a) −32 … +31; 100101, 010011, 110111 · b) 111000 (−8), in 8 bits 11111000 · c) 011100: yes, there is overflow (−36 does not fit); 0 goes into the sign column and 1 comes out.

In 6 bits the sign bit weighs −25=−32-2^5 = -32. And when going from 6 to 8 bits you don’t add zeros: you repeat the sign bit.

What is wrong here?

Three solutions by classmates, each with a mistake. Before reading the explanation, try to find it.

Fragment 1: the −40 that wasn’t −40

Represent -40 in 8-bit two's complement:
  +40         = 00101000
  flipped     = 11010111
  Answer: -40 = 11010111

What is wrong? It stopped at the ones’ complement. It is missing the +1: 11010111 + 1 = 11011000. With weights the mistake shows: 11010111 = −128 + 64 + 16 + 4 + 2 + 1 = −41, one less than it should be. With the shortcut it wouldn’t have happened: copy the three zeros and the first 1 (1000) and flip 0010 → 1101: 11011000.

Confusing ones’ and two’s complement. If in doubt, check with the weights: the result must give exactly the number in the question.

Fragment 2: the carry that caused a scare

(-20) + (-30) in 8-bit two's complement:
     11101100
   + 11100010
   ----------
   1 11001110
  A carry comes out -> there is overflow.

What is wrong? The result is right (11001110 = −50), but the conclusion is not. In two’s complement the end carry is discarded and says nothing. Two negatives have given a negative, so there is no overflow: −50 fits easily in −128 … +127.

Fragment 2: a carry is not overflow11101100 (−20) plus 11100010 (−30) gives 11001110, −50, with an end carry. Two negatives gave a negative: there is no overflow; the carry is simply discarded.carries11−2011101100−20−3011100010−30+result11001110−501end carry: discardednegative + negative = negative → no overflow
For overflow you look at the sign, never at the carry.

Using the carry as an overflow warning. That worked in unsigned binary; with a sign you look at the sign.

Fragment 3: the shortcut done backwards

Two's complement of +88 (01011000) with the shortcut:
  copy up to the first 1 -> 01
  flip the rest          -> 100111
  Answer: 01100111

What is wrong? The shortcut is done from the right, not from the left. Starting from the right you copy 1000 and flip 0101 → 1010: 10101000 = −88. The answer in the fragment is not even negative: 01100111 is +103.

The two’s complement of a positive (other than 0) always starts with 1. If your result starts with 0, you have done something backwards.

Solutions

Level 1

a) Positive with its 8 bits, flip and add 1 (or the shortcut):

NumberPositiveTwo’s c.Check with weights
−130000110111110011−128 + 64 + 32 + 16 + 2 + 1 = −13
−640100000011000000−128 + 64 = −64
+9001011010(positive) 0101101064 + 16 + 8 + 2 = 90
−10000000111111111−128 + 127 = −1

For −64 the shortcut is immediate: copy 1000000 (the first 1 and the six zeros) and only flip the first bit.

Why the positive goes with all its 8 bits: two’s complement flips every bit of the register, the zeros on the left included, and those zeros are the ones that become the 1s of the sign.

Flipping 13 = 1101 with 4 bits: 0010 + 1 = 0011, and padding gives 00000011 = +3. A negative in two’s complement has to start with 1.

b) With the weight −128:

CodeSignSumValue
11101001−−128 + 64 + 32 + 8 + 1−23
01011010+64 + 16 + 8 + 2+90
10000001−−128 + 1−127
11111110−−128 + 64 + 32 + 16 + 8 + 4 + 2−2

Why with the weight −128 and not by undoing the two’s complement: both paths get there, but the weights path is a single sum. Undoing it is three steps (flip, add 1, read) and then you have to remember the minus sign.

Adding the first bit as +128. 11101001 gives 233 instead of −23: exactly 256 more, because the sign counts 128 forwards instead of 128 backwards.

c) 9 = 1001 and C = 1100, so 9C₁₆ = 10011100. It starts with 1: negative. −128 + 16 + 8 + 4 = −100. Undoing the two’s complement: 01100100 = 100. Read as unsigned it would be 156, but the question says two’s complement (my story from the beginning).

Converting 9C₁₆ to binary is not a detour: it is how you see the sign bit. And you can already see it in the first digit: 0 to 7 start with 0, and 8 to F start with 1. Since 9 is greater than 7, it is negative before you write a single bit.

In 8-bit two’s complement, a code that starts with 1 is worth its unsigned reading minus 256: 156 − 256 = −100. My 156 was not far off, it just needed the subtraction.

d) With the formula [−2n−1, 2n−1−1]\left[-2^{n-1},\, 2^{n-1}-1\right]: with 5 bits, −16 … +15; with 12 bits, −2048 … +2047.

It also comes out without the formula, and you can see why the range is not symmetric. With 5 bits there are 32 codes: the 16 that start with 0 are 0 … +15 and the 16 that start with 1 are −16 … −1. The 0 takes up one of the «positive» slots. With 12 bits, 4096 codes, half and half.

Writing −16 … +16. The +16 would need one more bit.

Level 2

54 = 00110110, 73 = 01001001, 74 = 01001010, 64 = 01000000 (−64 = 11000000), 65 = 01000001 (−65 = 10111111), 25 = 00011001 and 90 = 01011010 (−90 = 10100110).

The plan before adding: do the sum in decimal and check whether it fits in −128 … +127. You will know which sums overflow before writing a single carry.

SumIn decimalDoes it fit?
a) 54 + 73127Yes, exactly the maximum
b) 54 + 74128No
c) (−64) + (−64)−128Yes, exactly the minimum
d) (−64) + (−65)−129No
e) 25 − 90−65Yes

a) 54 + 73.

carries      . . . . . . . .
             0 0 1 1 0 1 1 0    +54
           + 0 1 0 0 1 0 0 1    +73
           -----------------
             0 1 1 1 1 1 1 1    +127

There are no carries at all. Positive + positive = positive: no overflow. 127 is exactly the maximum.

b) 54 + 74.

carries      1 1 1 1 1 1 . .
             0 0 1 1 0 1 1 0    +54
           + 0 1 0 0 1 0 1 0    +74
           -----------------
             1 0 0 0 0 0 0 0    −128   (overflow)

Two positives have given 10000000, which starts with 1: overflow. 128 does not fit (the maximum is 127). No end carry.

This part is there to take apart the obvious idea: there is no end carry and yet there is overflow. In two’s complement you check whether the sign makes sense, and two positives cannot give a negative.

«No end carry, so no overflow: −128». That −128 is the 128 that does not fit, minus 256.

c) (−64) + (−64).

carries      1 . . . . . . .
             1 1 0 0 0 0 0 0    −64
           + 1 1 0 0 0 0 0 0    −64
           -----------------
         [1] 1 0 0 0 0 0 0 0    −128
         ^ end carry: discarded

End carry, which is thrown away. Two negatives have given 10000000 = −128, negative: no overflow. −128 is exactly the minimum.

d) (−64) + (−65).

carries      . . . . . . . .
             1 1 0 0 0 0 0 0    −64
           + 1 0 1 1 1 1 1 1    −65
           -----------------
         [1] 0 1 1 1 1 1 1 1    +127   (overflow)
         ^ end carry: discarded

End carry and, besides, two negatives have given 01111111, positive: overflow. −129 does not fit. A 0 goes into the sign column and a 1 comes out.

Compare c) and d) through the carries of the sign column. In c), the column next to it does 1 + 1 and passes a 1 on, and another 1 comes out of the sign: equal, no overflow. In d), the column next to it does 1 + 0 and passes nothing on, and a 1 comes out of the sign: different, overflow. The end carry is the same in both; what changes is what goes in. And it gives +127 because −129 + 256 = 127.

e) 25 − 90 = 25 + (−90).

carries      . . . . . . . .
             0 0 0 1 1 0 0 1    +25
           + 1 0 1 0 0 1 1 0    −90
           -----------------
             1 0 1 1 1 1 1 1    −65

Different signs: there cannot be overflow. 10111111 = −128 + 63 = −65, and 25 − 90 = −65.

Why add the opposite and not subtract with borrows: in two’s complement a subtraction is an addition, the one the circuit does. And with different signs there is nothing to check: the result always lies between the two numbers (between −90 and +25), and if both fit, whatever is in between fits too.

Level 3

a) With 6 bits, from −25=−32-2^5 = -32 to 25−1=312^5 – 1 = 31. The codes:

NumberPositive (6 bits)Two’s c.
−27011011100101
+19010011(positive) 010011
−9001001110111

Check of −27 with 6-bit weights: −32 + 4 + 1 = −27.

Writing 27 with the bits it has, 11011, and flipping: 00100 + 1 = 00101, which in 6 bits is 000101 = +5. The positive goes with the panel’s 6 bits.

b) (−27) + 19.

carries      . . 1 1 1 .
             1 0 0 1 0 1    −27
           + 0 1 0 0 1 1    +19
           -------------
             1 1 1 0 0 0    −8

Different signs, no overflow. 111000 = −32 + 16 + 8 = −8. To convert it to 8 bits, repeat the sign bit: 11111000 (−128 + 64 + 32 + 16 + 8 = −8). With zeros, 00111000 would be +56.

Why the sign bit is repeated: in 6 bits it weighed −32. In 8 bits, the sign and the two new 1s add up to −128 + 64 + 32 = −32, the same as before. With zeros, that bit would weigh +32 and you would get +56.

c) (−27) + (−9).

carries      . . 1 1 1 .
             1 0 0 1 0 1    −27
           + 1 1 0 1 1 1    −9
           -------------
         [1] 0 1 1 1 0 0    +28   (overflow)
         ^ end carry: discarded
Level 3, part c): overflow in 6 bitsIn 6-bit two's complement, 100101 (−27) plus 110111 (−9) gives 011100, +28, with an end carry: two negatives gave a positive, so there is overflow (−36 does not fit in −32 … +31). Into the sign column goes 0 and out comes 1.carries111−27100101−27−9110111−9+result011100+28 ?1end carry: discardedsignnegative + negative = positive → overflowin 0 and out 1 at the sign: different
Here there are a carry and overflow at the same time, but for different reasons.

Two negatives have given 011100, which starts with 0 (+28): overflow. −36 does not fit in −32 … +31. By the carries: a 0 goes into the sign column (the column next to it, 0 + 1, produces no carry) and a 1 comes out (1 + 1 in the sign): different, overflow. Both ways say the same. And the number you get, +28, is −36 + 64: the 6-bit wheel has gone round once.

The plan: −27 + (−9) = −36 and the panel only goes down to −32, so there will be overflow. The carries, from the right:

ColumnBitsCarry inWritesCarry out
1st1 + 1001
2nd0 + 1101
3rd1 + 1111
4th0 + 0110
5th0 + 1010
6th (sign)1 + 1001 (discarded)

Practice quiz

Twenty questions on the whole topic. They don’t count for anything: they mark themselves, explain each answer and you can repeat them as many times as you like. Write binaries without spaces (11110011) and negatives with the keyboard hyphen in front (-13).

Question 1Single choice

What is the 8-bit two’s complement of −19?

  1. 11101101
  2. 11101100
  3. 10010011
  4. 01101101
Solution

Answer: 11101101

Write +19 with 8 bits (00010011), flip it and add 1. With weights: −128 + 64 + 32 + 8 + 4 + 1 = −19.

Question 2Calculation

Write in 8-bit two’s complement (no spaces):

Number8-bit two’s c.
−100
−128
−33
Solution
Number8-bit two’s c.
−10010011100
−12810000000
−3311011111

100 = 01100100 → flipped 10011011 → plus 1: 10011100. −128 is 10000000 (−128 + 0). 33 = 00100001 → with the shortcut, copy the last 1 and flip the rest: 11011111.

Question 3Calculation

What decimal value do these codes have in 8-bit two’s complement? Type the minus sign with the keyboard hyphen (-56).

CodeDecimal value
11001000
10111111
01111111
Solution
CodeDecimal value
11001000-56
10111111-65
01111111127

With the first bit weighing −128: 11001000 = −128 + 64 + 8 = −56; 10111111 = −128 + 63 = −65; 01111111 starts with 0 and is 127, the 8-bit maximum.

Question 4Short answer

An 8-bit register holds F3₁₆ in two’s complement. Which decimal number is it?

Solution

Answer: -13

F3₁₆ = 11110011. It starts with 1: negative. −128 + 64 + 32 + 16 + 2 + 1 = −13 (read as unsigned it would be 243, which does not fit with a sign).

Question 5Short answer

And A0₁₆, also in 8-bit two’s complement?

Solution

Answer: -96

A0₁₆ = 10100000 = −128 + 32 = −96.

Question 6True or false

True or false (two’s complement)?

  1. There is only one representation of zero.
  2. The 8-bit range is from −127 to +127.
  3. The two’s complement of 10000000 is 10000000.
  4. If an end carry comes out, there is overflow.
  5. Adding two numbers of different sign never overflows.
Solution
  • T — There is only one representation of zero.
  • F — The 8-bit range is from −127 to +127.
  • T — The two’s complement of 10000000 is 10000000.
  • F — If an end carry comes out, there is overflow.
  • T — Adding two numbers of different sign never overflows.

The 8-bit range is −128 … +127 (−127 … +127 is the ones’ complement and sign-magnitude one). −128 has no opposite because +128 does not fit. The end carry is discarded and warns of nothing: overflow is read from the sign.

Question 7Single choice

In 8-bit two’s complement, what happens when adding 100 + 27?

  1. It gives 01111111 (+127) with no overflow
  2. It gives 01111111 and there is overflow
  3. It gives 10000000 and there is overflow
  4. An end carry comes out that must be added
Solution

Answer: It gives 01111111 (+127) with no overflow

01100100 + 00011011 = 01111111. Positive + positive = positive: no overflow.

Question 8Single choice

And when adding 100 + 28 in 8-bit two’s complement?

  1. It gives 10000000, there is overflow and no end carry
  2. It gives 10000000 = −128 and it is correct
  3. There is overflow because an end carry comes out
  4. It gives 010000000 with 9 bits
Solution

Answer: It gives 10000000, there is overflow and no end carry

01100100 + 00011100 = 10000000. The real sum is 128 and the maximum is 127: overflow, even though there is no end carry.

Question 9Multiple · wrong ticks subtract

Which of these 8-bit two’s complement additions overflow?

  1. 100 + 28
  2. (−127) + (−2)
  3. (−1) + (−1)
  4. (−70) + 70
  5. 60 + (−61)
Solution

Answer: 100 + 28 · (−127) + (−2)

Only additions of two numbers with the same sign whose result falls outside −128 … +127 overflow. Additions with different signs never do.

Question 10Calculation

Work out (−1) + (−1) in 8-bit two’s complement and fill in:

Result (8 bits)End carry (0 or 1)Overflow? (Yes or No)
Solution
Result (8 bits)End carry (0 or 1)Overflow? (Yes or No)
111111101No

11111111 + 11111111 = 1 11111110. The end carry is thrown away and 11111110 = −2 is left. Two negatives give a negative: no overflow.

Question 11Fill in the gaps

Fill in the gaps:

To get the two’s complement of a number you ____ all its bits and add 1. In an addition, the end carry is ____ and overflow is detected by looking at the ____ of the result.

Words:

  • discarded
  • added on the right
  • copy
  • flip
  • carry
  • sign
Solution

To get the two’s complement of a number you flip all its bits and add 1. In an addition, the end carry is discarded and overflow is detected by looking at the sign of the result.

Flipping and adding 1 is the definition. The end carry is not used (in ones’ complement it came back) and the sign tells you about overflow.

Question 12Match

Match each format with what is done in an addition:

Two’s complement
Ones’ complement
Unsigned binary
Sign-magnitude

Definitions:

  • First look at the signs and compare magnitudes
  • The end carry is discarded
  • The end carry comes back and is added on the right
  • The end carry warns of overflow
  • The end carry is multiplied by 2
Solution
  • Two’s complement → The end carry is discarded
  • Ones’ complement → The end carry comes back and is added on the right
  • Unsigned binary → The end carry warns of overflow
  • Sign-magnitude → First look at the signs and compare magnitudes

Only in unsigned binary is the end carry the overflow warning. In ones’ complement it comes back, in two’s complement it is thrown away and in sign-magnitude you don’t add blindly.

Question 13Order

Order the steps to read an 8-bit two’s complement code that starts with 1 (without using the weights):

  1. Look at the first bit: it is 1, the number is negative
  2. Put the minus sign in front
  3. Add 1
  4. Read the result as plain binary
  5. Flip every bit
Solution

Correct order:

  1. Look at the first bit: it is 1, the number is negative
  2. Flip every bit
  3. Add 1
  4. Read the result as plain binary
  5. Put the minus sign in front

Undoing the two’s complement is taking the two’s complement again: flip and add 1. What you get is the magnitude, and the number is its opposite.

Question 14Calculation

What is the minimum number of bits needed to represent each number in two’s complement?

NumberMinimum bits
−64
+64
−129
+127
Solution
NumberMinimum bits
−647
+648
−1299
+1278

With 7 bits the range is −64 … +63: −64 fits but +64 does not. With 8 bits, −128 … +127 (+127 fits). −129 needs 9 bits (−256 … +255).

Question 15Single choice

In 4-bit two’s complement, what does (−3) + (−6) give?

  1. 0111, with overflow
  2. 0111 = +7, correct
  3. 1001 = −9
  4. 0111, no overflow because the carry is thrown away
Solution

Answer: 0111, with overflow

1101 + 1010 = 1 0111. The carry is thrown away and 0111, positive, is left: overflow.

Question 16Single choice

−5 in 4-bit two’s complement is 1011. How is it written in 8 bits?

  1. 11111011
  2. 00001011
  3. 10001011
  4. 10110000
Solution

Answer: 11111011

When going to more bits the sign bit is repeated: 1111 1011 = −128 + 64 + 32 + 16 + 8 + 2 + 1 = −5.

Question 17Short answer

Use the shortcut to get the two’s complement of 00110100 (+52). Write the 8 bits without spaces.

Solution

Answer: 11001100

From the right, copy 100 (the two zeros and the first 1) and flip 00110 → 11001: 11001100 = −128 + 64 + 8 + 4 = −52.

Question 18Single choice

In which of these 4-bit two’s complement additions is there overflow?

  1. 7 + 1
  2. (−8) + 1
  3. (−4) + (−4)
  4. (−3) + 3
Solution

Answer: 7 + 1

In 4 bits the range is −8 … +7. 7 + 1 = 8 does not fit; −4 − 4 = −8 does.

Question 19Single choice

An 8-bit register holds 11111111. What is it worth if it is in two’s complement?

  1. −1
  2. −127
  3. −0
  4. 255
Solution

Answer: −1

The same code means different things in each format. In two’s complement, 11111111 is −1, the code you get when you go back 1 from 00000000.

Question 20Short answer

Subtract 30 − 75 in 8-bit two’s complement (adding the two’s complement of 75). Write the result in binary, without spaces.

Solution

Answer: 11010011

Two’s complement of 75 = 10110101. 00011110 + 10110101 = 11010011 = −128 + 64 + 16 + 2 + 1 = −45, with no end carry and no overflow.

What next?

Two’s complement does not stay on paper. In MIPS every register stores integers in two’s complement: that is why lb repeats the sign bit when it loads a byte and lbu does not, as you saw in MIPS load, arithmetic and logic. If you want to see how additions and subtractions with negative numbers behave inside the processor, the IC1 practical mock exam is a good place to try it with the website’s MIPS environment.

With this topic we close integers. In the next one we move on to numbers with decimals: IEEE 754 floating point, the format of float and double, with its sign, its biased exponent and its mantissa.

To check your solutions, do the sums in the One number, every form simulator choosing C2 and the bits of the exercise; its «Test yourself» section brings new sums where you have to say whether they overflow.

IC1 exam coming up?The theory and MIPS packs with new solved exams, their cheat sheets, blank exams and .s solutions, for free.See the pack

Cheat sheet: two’s complement

The essentials in 30 seconds

  • Negative in two’s complement: positive with n bits → flip → add 1 (or copy from the right up to the first 1 and flip the rest).
  • Reading a code: if it starts with 0, plain binary; if it starts with 1, weight −2n−1-2^{n-1} on that bit (or take the two’s complement again and add the minus).
  • Range with n bits: −2n−1-2^{n-1} … 2n−1−12^{n-1}-1. Only one zero.
  • Adding: as in plain binary. The end carry is thrown away.
  • Subtracting: A−B=A+C2(B)A – B = A + \mathrm{C2}(B).
  • Overflow: same sign in the addends and another in the result. With different signs, never.

I want to…

I want to…HowExample (8 bits)
Get −xFlip x and add 145 = 00101101 → 11010011
Use the shortcutCopy up to the first 1 from the right and flip the rest88 = 01011000 → 10101000
Read a negativeWeight −128 on the first bit11010011 = −128 + 83 = −45
Read a hex in two’s c.Convert to 8 bits and look at the first bit9C₁₆ = 10011100 = −100
Go to more bitsRepeat the sign bit1010 (−6) → 11111010
SubtractAdd the two’s c. of the subtrahend30 − 75 = 00011110 + 10110101
Know if it overflowsSigns in and out, or carry into and out of the sign120 + 30 → 10010110: yes

Ranges worth knowing

BitsTwo’s complement range
4−8 … +7
6−32 … +31
8−128 … +127
16−32,768 … +32,767
32−2,147,483,648 … +2,147,483,647

Templates

An 8-bit two’s complement addition with everything an exam asks for:

carries      1 1 . 1 1 . . .
             0 0 1 0 1 1 0 1    +45
           + 1 1 1 0 1 1 0 0    −20
           -----------------
         [1] 0 0 0 1 1 0 0 1    +25
         ^ end carry: discarded
Signs: + and − -> cannot overflow.

The exam’s chained addition, in three phases: convert the three numbers (two’s complement of the negatives), add the brackets and then the third one, and check overflow in both additions.

Symptom / likely cause

SymptomLikely cause
Your −x is one less than it should beYou stopped at the ones’ complement (the +1 is missing)
The two’s complement of a positive starts with 0Shortcut from the left, or leading zeros missing
A subtraction result is one too bigYou added the end carry as in ones’ complement
An 8-bit code gives you more than 127You read it as unsigned: look at the first bit
−6 becomes +10 when converted to 8 bitsYou extended with zeros instead of the sign
You mark overflow in every subtractionYou are looking at the end carry, not the sign

Before handing in, ask yourself

  1. Have I written every number with the bits the question asks for?
  2. Have I checked each two’s complement with the weights (or with the other method)?
  3. Have I thrown the end carry away without adding it?
  4. Have I looked at the sign in every addition to decide on overflow?
Keep goingAll Computers articles

Did this article help you? Here is how you can support SergioLearns →

Ready for the exam?IC1 practical mock exam — MIPS in QtSpim with other data, subroutines and keyboard input (and why part 1 decides almost everything)