Binary arithmetic — solved exercises with the lift scale, trips in binary, a 6-bit panel and a practice quiz (and the overflow I missed by looking at the carry)
In an IC1 mock exam there was a ones’ complement addition with the usual box: «Does overflow occur? Yes / No». It was 100 + 50 in 8 bits. I added them, got 10010110 and looked for the end carry: there was none. I ticked «No» as calmly as could be and moved on to the next one. When I marked it, the right box was «Yes»: 10010110 starts with 1, it is a negative number, and two positives cannot add up to a negative. 150 does not fit in −127 … +127. I had learnt the carry rule for unsigned numbers and was applying it where it did not belong. Since then, as soon as I see «signed», the first thing I look at is the leftmost bit.
These are the exercises of the third paper topic of IC1. You already have the binary arithmetic theory (additions, subtractions, multiplication, division, sign-magnitude and ones’ complement) and the practice with four problems solved step by step. Now it is your turn, with the shopping center lift as always: the scale, the day’s trips and the new 6-bit panel. Then, three solutions with a hidden mistake, the full solutions, a practice quiz and the cheat sheet.
Table of Contents
How to use this article
- Try each level on paper, without a calculator (there is none in the exam), with the method of the practice: data with its format, method, calculations with the row of carries or borrows, and a check in decimal.
- If you get stuck, open the hint for that level. Just one.
- Before looking at the solutions, do «What’s wrong here?»: finding the mistake in someone else’s solution is exactly what helps you not to make it.
- Compare your working with the step-by-step solution, not just the final result, and finish with the quiz.
Level 1: the lift scale
The scale stores the kilos unsigned in 8 bits. Calculate in binary, with the row of carries or borrows, and check in decimal:
a) A person of 90 kg gets in and then another of 55 kg: .
b) On the next floor the 55 kg person gets out: subtract from the result of a).
c) Instead of anyone getting out, a 120 kg trolley comes in (). What does the scale show? Is there overflow?
Expected result: a) 10010001 (145); b) 01011010 (90); c) 00001001, the scale shows 9 kg, with an end carry: there is overflow (the real weight is 265 kg).
In a) there is a run of six carries: in column 4 three ones meet. In c), before adding, think whether 145 + 120 fits in 8 bits.
Level 2: trips in binary
A delivery driver goes up 27 times a day from the street to floor 10.
a) How many floors does he travel going up? Calculate .
b) The lift covers 12 floors in a full trip (from the street to floor 12). How many full trips is the result of a) worth, and how many floors are left over? Divide by , with quotient and remainder.
Expected result: a) , 270 floors; b) quotient (22 trips) and remainder (6 floors).
In a), the multiplier 1010 has two zeros: two of the four partials are rows of zeros, but they count for the shift. In b), write one quotient digit for each bit you bring down from the first one where 1100 fits.
Level 3 (challenge): the new 6-bit panel
The shopping center has replaced the floor panel with a 6-bit signed one.
a) What is the range in sign-magnitude and in ones’ complement with 6 bits?
b) Write the floors −3, +12 and −17 (the new car park is very deep) in 6-bit sign-magnitude and C1.
c) The lift is on +12 and goes down 17 floors. Calculate in C1, adding the ones’ complement of 17.
d) Calculate in 6-bit C1. Is there overflow? How do you know?
e) Calculate c) again, but in sign-magnitude, with the rule of signs.
Expected result: a) from −31 to +31 in both; b) −3: 100011 and 111100; +12: 001100 in both; −17: 110001 and 101110; c) 111010, −5; d) 011010 after the end-around, +26: there is overflow; e) 100101, −5.
In d), look at the sign of the two addends and that of the result, not at the end carry (there is one, and it is given back).
What’s wrong here?
Three solutions by classmates. Each one has a mistake. Before reading the explanation, try to find it yourself.
Fragment 1: the subtraction without borrows
A classmate has to work out how many floors there are between floor 20 and floor 11, in binary: . Their working:
1 0 1 0 0 20
− 0 1 0 1 1 − 11
-----------
1 1 1 1 1 31
Predict: what have they done in each column?
Explanation. In each column they wrote «the bit that is different»: 0 − 1 → 1, 0 − 1 → 1, 1 − 0 → 1, 0 − 1 → 1, 1 − 0 → 1. They applied the rule 0 − 1 = 1 correctly… but forgot that it leaves a borrow for the next column. Without borrows, the result makes no sense: 31 floors between floor 20 and floor 11.
Writing the 1 of 0 − 1 and not noting the borrow. The full rule is «0 − 1 = 1 and I owe 1».
With the borrows written down (they are added to the subtrahend of the next column):
borrows 1 1 1
1 0 1 0 0 20
− 0 1 0 1 1 − 11
-----------
0 1 0 0 1 9
Column 0: 0 − 1, borrow: 1. Column 1: 0 − (1 + 1), borrow: 0. Column 2: 1 − (0 + 1) = 0. Column 3: 0 − 1, borrow: 1. Column 4: 1 − (0 + 1) = 0. Result 01001, 9 floors, and 20 − 11 = 9.
If the result of a subtraction is greater than the minuend, you have certainly lost a borrow. Subtracting cannot make an unsigned number grow.
Fragment 2: the carry that was thrown away
Another classmate calculates (+9) + (−4) in 8-bit ones’ complement:
0 0 0 0 1 0 0 1 +9
+ 1 1 1 1 1 0 1 1 −4
-----------------
1 0 0 0 0 0 1 0 0
→ I keep 00000100 = +4
Predict: 9 − 4 should give 5. Where did the unit go?
Explanation. The addition is done correctly and produces an end carry, the leftmost bit. She threw it away, as is done in two’s complement. In ones’ complement that carry wraps around and is added to the result:
00000100 + 1 = 00000101, +5. Look at the drawing: the result without the end-around is exactly one unit short, and whenever the carry is thrown away in C1 the same happens.
Mixing up the rules of ones’ complement and two’s complement. In C1, the end carry is added; in two’s complement (the next topic), it is discarded.
Fragment 3: the carry as a warning
A third classmate has to say whether (+100) + (+50) overflows in 8-bit ones’ complement:
0 1 1 0 0 1 0 0 +100
+ 0 0 1 1 0 0 1 0 +50
-----------------
1 0 0 1 0 1 1 0
→ there is no end carry: no overflow
Predict: is the addition right? And the conclusion?
Explanation. The addition is right. The conclusion is not (it is my story from the beginning). The result starts with 1: it is negative, −105 (flip → 01101001 = 105). Two positives cannot add up to a negative, so there is overflow: 150 does not fit in −127 … +127. The end carry is not the warning with signed numbers: it was on the scale, which has no sign.
And the opposite case exists too: (−20) + (−30) gives 11101011 + 11100001 = 1 11001100, with an end carry, and after the end-around 11001101 = −50, which is correct. A carry without overflow.
Using «there is an end carry» as a sign of overflow in signed numbers. The sign is: two addends with the same sign and a result with the opposite sign.
Solutions
Level 1
a) 90 + 55, from right to left:
carries 1 1 1 1 1 1
0 1 0 1 1 0 1 0 90
+ 0 0 1 1 0 1 1 1 + 55
-----------------
1 0 0 1 0 0 0 1 145
Column 0: 0 + 1 = 1. Column 1: 1 + 1 = 10, write 0 and carry 1. Column 2: 0 + 1 + 1 = 10. Column 3: 1 + 0 + 1 = 10. Column 4: 1 + 1 + 1 = 11, three ones: write 1 and carry 1. Columns 5 and 6: 0 + 1 + 1 and 1 + 0 + 1, 10 twice. Column 7: 0 + 0 + 1 = 1. Check: 10010001 = 128 + 16 + 1 = 145.
Column 4 is the one that decides whether the addition comes out right. Up to there, each column had at most two ones; here three arrive (the one from 90, the one from 55 and the carry from column 3), and 1 + 1 + 1 = 3, which in binary is 11: one 1 stays and the other goes up.
Treating the three ones as if they were two: writing 0 and carrying 1. The sum comes out as 10000001 = 129 instead of 145, exactly 16 less, the value of column 4. If the decimal check is off by a power of 2, look at that column.
b) 145 − 55:
borrows 1 1 1 1 1 1
1 0 0 1 0 0 0 1 145
− 0 0 1 1 0 1 1 1 − 55
-----------------
0 1 0 1 1 0 1 0 90
| Column | Minuend | Subtrahend + borrow | Result | Borrows? |
|---|---|---|---|---|
| 0 | 1 | 1 | 0 | No |
| 1 | 0 | 1 | 1 | Yes |
| 2 | 0 | 1 + 1 = 2 | 0 | Yes |
| 3 | 0 | 0 + 1 = 1 | 1 | Yes |
| 4 | 1 | 1 + 1 = 2 | 1 | Yes |
| 5 | 0 | 1 + 1 = 2 | 0 | Yes |
| 6 | 0 | 0 + 1 = 1 | 1 | Yes |
| 7 | 1 | 0 + 1 = 1 | 0 | No |
Result 01011010 = 64 + 16 + 8 + 2 = 90: the scale shows again what it had before, as it should.
The approach before subtracting: b) undoes a), so the result has to be 90, the first addend of a), 01011010. Knowing it before you start gives you the check for free.
And the «Result» column of the table always comes out the same way: minuend minus (subtrahend + borrow). When it is not enough, the column borrows 1 from the one on its left, and that 1 is worth 2 here, just as in decimal borrowing a ten gives you 10 units. In column 2: 0 does not reach 2, it borrows, 0 + 2 − 2 = 0. In column 4: 1 does not reach 2, it borrows, 1 + 2 − 2 = 1.
c) 145 + 120:
carries 1 1 1
1 0 0 1 0 0 0 1 145
+ 0 1 1 1 1 0 0 0 + 120
-----------------
1 0 0 0 0 1 0 0 1
Columns 0 to 3 give no carry; in column 4, 1 + 1 = 10. Then 0 + 1 + 1, 0 + 1 + 1 and, in column 7, 1 + 0 + 1 = 10: the last carry goes out on the left and does not fit. The scale keeps the 8 rightmost bits, 00001001, and shows 9 kg. Since it is unsigned, the end carry is the warning: there is overflow. Check: 145 + 120 = 265, and 265 − 256 = 9.
Here the approach comes before the sum: with 8 unsigned bits the maximum is 11111111 = 255, and 145 + 120 = 265 goes over it. You know there will be overflow before writing a single carry; the addition only tells you what the scale shows. And why it shows 9: the carry that is lost is worth 2⁸ = 256, so the scale shows 265 − 256.
The end carry is only the warning when the numbers are unsigned, as on the scale. In Level 3, signed and in C1, the warning is a different one: the sign of the result. That is why in c) of Level 3 there is no end carry and in d) there is one, and the overflow is in d) because of the sign, not because of the carry.
Level 2
a) 11011 × 1010 (bits 1 and 3 of the multiplier are 1):
1 1 0 1 1 27
× 1 0 1 0 × 10
-------------------
0 0 0 0 0 (bit 0 = 0: zeros)
1 1 0 1 1 (bit 1 = 1: copy shifted 1)
0 0 0 0 0 (bit 2 = 0: zeros)
+ 1 1 0 1 1 (bit 3 = 1: copy shifted 3)
-------------------
1 0 0 0 0 1 1 1 0 270
The partials of bits 0 and 2 are zeros, but they take up their place: that is why the one for bit 3 is shifted three places. The addition, two at a time: 110110 + 11011000 = 100001110. Check: 256 + 8 + 4 + 2 = 270, and 27 × 10 = 270.
Why 1010 goes underneath and not 11011: each 1 in the multiplier is a copy you have to add, and 1010 only has two ones. The other way round you get four copies:
| Route | Copies to add | Values | Total |
|---|---|---|---|
| 11011 × 1010 (the one in the exercise) | 110110 and 11011000 | 54 + 216 | 270 |
| 1010 × 11011 (the other way round) | 1010, 10100, 1010000 and 10100000 | 10 + 20 + 80 + 160 | 270 |
Both give 270, but the first is two rows and a single addition; the second, four rows with more carries to get wrong. When you can choose, the one with fewer ones goes underneath.
b) 100001110 ÷ 1100:
| Bits brought down | Does 1100 fit? | Digit | What is left |
|---|---|---|---|
| 1, 10, 100, 1000 | No | (leading zeros) | 1000 |
| 10000 | Yes | 1 | 10000 − 1100 = 100 |
| 1001 | No | 0 | 1001 |
| 10011 | Yes | 1 | 10011 − 1100 = 111 |
| 1111 | Yes | 1 | 1111 − 1100 = 11 |
| 110 | No | 0 | 110 |
Quotient 10110 = 16 + 4 + 2 = 22 and remainder 110 = 6. Check: 22 · 12 + 6 = 264 + 6 = 270. That is 22 full trips and 6 more floors.
The approach to division is the usual one: repeated subtraction. You keep bringing bits down until 1100 fits, and from that moment on each bit you bring down gives a digit of the quotient, whether it fits or not. The dividend has 9 bits and the first chunk where it fits has 5 (10000), so there are 4 bits left to bring down: the quotient has 1 + 4 = 5 digits. Knowing that beforehand is another check.
Not writing the 0 when it does not fit (in the 1001 row or the 110 row). You are left with the ones, 111 = 7, and the check gives it away: 7 · 12 = 84, far from 270.
Level 3
a) With n = 6 bits, the magnitude has 5: , the same in sign-magnitude and in C1.
b) First the magnitudes in 5 bits: 3 = 00011, 12 = 01100, 17 = 10001.
| Floor | Sign-magnitude | Ones’ complement |
|---|---|---|
| −3 | 1 00011 → 100011 | flip 000011 → 111100 |
| +12 | 001100 | 001100 |
| −17 | 1 10001 → 110001 | flip 010001 → 101110 |
In C1 you flip all 6 bits of the positive number, sign included: +17 = 010001 becomes 101110. That is why the leading 0 turns into the sign’s 1 and you do not need to add it separately.
Flipping the sign-magnitude form. If you start from −17 = 110001 and flip it, you get 001110, which starts with 0 and is +14. The C1 of a negative number always comes from the positive one.
c) , with the C1 of 17:
carries 1 1
0 0 1 1 0 0 +12
+ 1 0 1 1 1 0 −17
-------------
1 1 1 0 1 0 −5
There is no end carry. The result starts with 1: negative. Flip 111010 → 000101 = 5 → −5. And 12 − 17 = −5. The addends have different signs, so there cannot be overflow.
Why add rather than subtract directly: in C1 a subtraction is done as adding the opposite, so there is only one operation to learn. The approach before the sum helps too: 12 − 17 = −5, so you expect a result that starts with 1.
d) . First the −20: 20 = 010100, flipped 101011.
carries 1 1 1
1 0 1 1 1 0 −17
+ 1 0 1 0 1 1 −20
-------------
1 0 1 1 0 0 1
+ 1 (end-around)
-------------
0 1 1 0 1 0 +26 ?
There is an end carry, which is given back: 011001 + 1 = 011010, which starts with 0, +26. Two negatives have given a positive: there is overflow. I know it from the sign, not from the carry. The real result, −37, does not fit in −31 … +31.
Here the approach saves you the surprise: before adding, 17 + 20 = 37 and the panel only reaches 31 on each side, so −37 does not fit and there will be overflow. The addition shows which number comes out instead, and it is not just any number: in 6-bit C1 the count wraps around every 63 (2⁶ − 1), and −37 + 63 = 26. It is the same wrap-around that makes −5 be written 111010, which is 58 = 63 − 5.
e) In sign-magnitude: +12 = 001100 and +17 = 010001. To subtract, the subtrahend’s sign is flipped: (+12) + (−17). Different signs: subtract the smaller magnitude from the larger, 10001 − 01100 = 00101 (17 − 12 = 5), and use the sign of the larger one, the 17, which is now negative: 100101, −5. The same number as in c), written in another format (in C1 it was 111010).
Practice quiz
Twenty questions to go over the whole topic: additions and subtractions with carries and borrows, multiplication and division, unsigned overflow, sign-magnitude and ones’ complement. It does not count for anything (the IC1 exam is written, not multiple choice): it is there so you can see what you have clear and what you do not. You can repeat it as many times as you like; each answer comes with its explanation. In the boxes, write binary numbers without spaces.
In a binary addition, a column has 1 + 1 to add and a carry also comes in from the previous column. What is written and what goes to the next column?
- 1 is written and there is a carry of 1
- 0 is written and there is a carry of 1
- 1 is written and there is no carry
- 0 is written and there is a carry of 2
Solution
Answer: 1 is written and there is a carry of 1
1 + 1 + 1 = 3, and : the right bit (1) is written in the column and the left one (1) is the carry. It is the case people forget most.
Calculate in plain (unsigned) binary and write the result without spaces and its decimal value.
| Operation | Result in binary | In decimal |
|---|---|---|
| 1011 + 0110 | ||
| 1101 − 0111 | ||
| 10110 + 01011 |
Solution
| Operation | Result in binary | In decimal |
|---|---|---|
| 1011 + 0110 | 10001 | 17 |
| 1101 − 0111 | 110 | 6 |
| 10110 + 01011 | 100001 | 33 |
1011 + 0110: 11 + 6 = 17 = 10001 (an end carry opens a new digit). 1101 − 0111: 13 − 7 = 6 = 110, with borrows in columns 1 and 2. 10110 + 01011: 22 + 11 = 33 = 100001.
Calculate in binary (write the point).
Solution
Answer: 10010.01
Line up the points and fill: 1100.11 + 0101.10. The result is 10010.01, worth 16 + 2 + 0.25 = 18.25, the same as 12.75 + 5.5.
About addition and subtraction in plain binary:
- In subtraction, 0 − 1 gives 1 and creates a borrow for the next column.
- In subtraction, the borrow is thrown away because there is no column to put it in.
- To add several numbers, you add them two at a time.
- To add two numbers with a binary point, you do not need to line up the points if they have the same total number of digits.
Solution
- T — In subtraction, 0 − 1 gives 1 and creates a borrow for the next column.
- F — In subtraction, the borrow is thrown away because there is no column to put it in.
- T — To add several numbers, you add them two at a time.
- F — To add two numbers with a binary point, you do not need to line up the points if they have the same total number of digits.
0 − 1 is worked out as 10 − 1 = 1, borrowing a unit from the next column: that borrow is added to the subtrahend of that column, not thrown away. Chained additions go two at a time (associative). And the points are always lined up: what has to match is the weight of each column, not the total number of digits.
How many borrows are needed in the subtraction ?
- 3
- 1
- 0
- 4
Solution
Answer: 3
8 − 1 = 7: 1000 − 0001 = 0111. The three borrows chain because columns 0, 1 and 2 have a 0 in the minuend.
Multiply and divide in binary. Write the results without spaces.
| Operation | Result |
|---|---|
| 101 × 11 | |
| 1110 ÷ 11: quotient | |
| 1110 ÷ 11: remainder |
Solution
| Operation | Result |
|---|---|
| 101 × 11 | 1111 |
| 1110 ÷ 11: quotient | 100 |
| 1110 ÷ 11: remainder | 10 |
101 × 11 = 5 × 3 = 15 = 1111 (partials 101 and 1010). 1110 ÷ 11 = 14 ÷ 3 = 4 remainder 2: quotient 100 and remainder 10. Check: 4 · 3 + 2 = 14.
Put in order the steps of each round of a binary long division:
- Bring down the next bit of the dividend
- Write 1 in the quotient if it fits, or 0 if it does not
- If it fitted, subtract the divisor
- Compare what you have with the divisor
Solution
Correct order:
- Bring down the next bit of the dividend
- Compare what you have with the divisor
- Write 1 in the quotient if it fits, or 0 if it does not
- If it fitted, subtract the divisor
Each round brings down a bit, compares, writes the quotient digit (also when it is 0) and, only if it fitted, subtracts. What is left is the starting point of the next round.
A lift scale stores kilos unsigned in 8 bits. It shows 200 kg and a 100 kg load comes in. What does it show now?
- 44 kg, and there is an end carry
- 300 kg
- 255 kg
- −44 kg
Solution
Answer: 44 kg, and there is an end carry
11001000 + 01100100 = 1 00101100: the end carry does not fit and the 8 bits that are left are worth 44. With unsigned numbers, the end carry is the overflow warning.
Which of these statements about overflow are correct?
- Unsigned, if there is an end carry there is overflow
- Signed, if two positives add up to a negative there is overflow
- Signed, if there is an end carry there is overflow
- When adding two numbers with different signs there is never overflow
Solution
Answer: Unsigned, if there is an end carry there is overflow · Signed, if two positives add up to a negative there is overflow · When adding two numbers with different signs there is never overflow
Carry and overflow only coincide for unsigned numbers. With a sign, the warning is the sign of the result: the same sign in the addends and the opposite in the result.
Write these numbers in 8 bits, without spaces.
| Number | Sign-magnitude | Ones’ complement |
|---|---|---|
| −20 | ||
| −7 |
Solution
| Number | Sign-magnitude | Ones’ complement |
|---|---|---|
| −20 | 10010100 | 11101011 |
| −7 | 10000111 | 11111000 |
20 = 00010100. In sign-magnitude only the sign bit changes: 10010100. In C1 every bit is flipped: 11101011. With 7 (00000111): 10000111 and 11111000.
What is the range of 8-bit sign-magnitude numbers?
- From −127 to +127
- From −128 to +127
- From 0 to 255
- From −255 to +255
Solution
Answer: From −127 to +127
With n bits, one bit is the sign and are left for the magnitude: . With 8 bits, −127 … +127, and zero appears twice.
Match each 8-bit code with its meaning:
| 00000000 | |
| 10000000 | |
| 11111111 | |
| 01111111 |
Definitions:
- −0 in sign-magnitude
- −128 in sign-magnitude
- +0 in sign-magnitude and in C1
- +127, the largest positive in both formats
- −0 in ones' complement
Solution
- 00000000 → +0 in sign-magnitude and in C1
- 10000000 → −0 in sign-magnitude
- 11111111 → −0 in ones’ complement
- 01111111 → +127, the largest positive in both formats
Both formats have two zeros: +0 (all zeros) and a −0, which in sign-magnitude is the sign with zero magnitude (10000000) and in C1 is the complement of 00000000 (11111111). −128 does not exist in either of them with 8 bits.
Which number is 11110101 in 8-bit ones’ complement?
- −10
- −117
- 245
- −11
Solution
Answer: −10
Two ways: flip (00001010 = 10) and add the sign, or weights with −128 (−11) and add 1 (−10). Both give −10.
Which decimal number is 10001010 in 8-bit sign-magnitude? (write the sign)
Solution
Answer: -10
Sign bit 1 (negative) and magnitude 0001010 = 8 + 2 = 10: −10.
Complete the rule for subtraction in ones’ complement:
To subtract, you add the ____ of the subtrahend to the minuend and, if there is an end carry, you ____ it to the result.
Words:
- discard
- add
- two's complement
- ones' complement
- sign-magnitude
Solution
To subtract, you add the ones’ complement of the subtrahend to the minuend and, if there is an end carry, you add it to the result.
In C1 subtraction becomes an addition with the ones’ complement of the subtrahend, and the end carry is given back by adding it on the right (in two’s complement, by contrast, it is discarded).
In 4-bit ones’ complement, what is (−3) + (−4)?
- 1000, which is −7, without overflow
- 0111, which is +7, with overflow
- 1001, which is −6
- It cannot be done: −7 does not fit in 4 bits
Solution
Answer: 1000, which is −7, without overflow
−3 = 1100 and −4 = 1011. The sum gives 10111: an end carry, which is added to 0111, leaving 1000. Two negatives give a negative, so there is no overflow.
About sign-magnitude and ones’ complement:
- Positive numbers are written the same way in both formats.
- In sign-magnitude you can add bit by bit without looking at the signs.
- To multiply in sign-magnitude, you multiply the magnitudes and the sign comes from the rule of signs.
- Ones’ complement has a single zero.
Solution
- T — Positive numbers are written the same way in both formats.
- F — In sign-magnitude you can add bit by bit without looking at the signs.
- T — To multiply in sign-magnitude, you multiply the magnitudes and the sign comes from the rule of signs.
- F — Ones’ complement has a single zero.
Positives start with 0 and are written as in plain binary in both. In sign-magnitude you have to compare signs before adding (otherwise −3 + 5 gives −8). And C1 has two zeros: 00000000 and 11111111.
Calculate 20 − 7 in 8-bit ones’ complement, adding the C1 of 7 (00010100 + 11111000).
| Item | Value |
|---|---|
| Is there an end carry? (1 = yes, 0 = no) | |
| Result in decimal |
Solution
| Item | Value |
|---|---|
| Is there an end carry? (1 = yes, 0 = no) | 1 |
| Result in decimal | 13 |
00010100 + 11111000 = 1 00001100. There is an end carry, which is added: 00001100 + 1 = 00001101 = 13. And 20 − 7 = 13.
In 4-bit ones’ complement you add 0101 (+5) and 0100 (+4). What happens?
- You get 1001 (−6): there is overflow because two positives give a negative
- You get 1001, which is +9
- There is no overflow because there is no end carry
- You get 0001 with an end carry
Solution
Answer: You get 1001 (−6): there is overflow because two positives give a negative
0101 + 0100 = 1001, with no end carry. The result starts with 1 (negative) and the addends were positive: overflow.
Which of these are real drawbacks of sign-magnitude and ones’ complement?
- Both have two representations of zero
- In sign-magnitude you have to compare signs and magnitudes before adding, which makes the circuits slow
- In ones’ complement you sometimes have to add the end carry, which complicates the adder
- In ones’ complement you cannot subtract numbers
Solution
Answer: Both have two representations of zero · In sign-magnitude you have to compare signs and magnitudes before adding, which makes the circuits slow · In ones’ complement you sometimes have to add the end carry, which complicates the adder
The two zeros, the comparisons of sign-magnitude and the end-around carry of C1 are exactly what two’s complement fixes, the next topic. Subtracting in C1 is precisely its strong point.
What next?
Binary arithmetic is underneath everything a processor does. If you want to see it working:
- In load, arithmetic and logic in MIPS,
add,subandaddiare exactly these additions and subtractions in a 32-bit register; andaddversusadduis the difference between reporting overflow or not. - In QtSpim you can see the results in binary and hexadecimal: go over how to read them in MIPS program structure and data.
- And when you want to test yourself with the full practical exam, there is the IC1 practical mock exam, which marks itself when you hand it in.
The next paper topic is two’s complement: the format computers really use, with a single zero, no end-around carry and its own overflow rule. Everything from today (adding in columns, the sign bit, looking at the sign for overflow) is used there from the very first line.
To check your solutions, do the operation in the One number, every form simulator choosing unsigned, SM or C1: you see each column with its carry and the C1 end-around carry; its «Test yourself» section brings new sums.
Cheat sheet: binary arithmetic
The essentials in 30 seconds
- Addition: 1 + 1 = 10 and 1 + 1 + 1 = 11. Subtraction: 0 − 1 = 1 and I owe 1.
- Multiplying: partials (copy or zeros) shifted and added. Dividing: one bit at a time, it fits (1) or not (0).
- Unsigned: range ; end carry = overflow.
- Sign-magnitude and C1: range , two zeros; overflow = impossible sign.
I want to…
| I want to… | How | Example (8 bits) |
|---|---|---|
| Add unsigned | Column by column, carries on top | 01001011 + 01000100 = 10001111 (75 + 68) |
| Subtract unsigned | Borrow added to the next subtrahend | 1100 − 0101 = 0111 (12 − 5) |
| Add with a point | Line up the points and fill with zeros | 1100.11 + 0101.10 = 10010.01 |
| Multiply | Copy if the bit is 1, zeros if 0, shifting | 1100 × 101 = 111100 (12 × 5) |
| Divide | Bring down bits; 1 and subtract if it fits, 0 if not | 11011 ÷ 110 = 100, remainder 11 |
| Negative in sign-magnitude | Flip only the sign bit | −3 = 10000011 |
| Negative in C1 | Flip every bit | −3 = 11111100 |
| Read a negative C1 | Flip and add the sign (or weights with −128 and + 1) | 11111100 → −3 |
| Subtract in C1 | Add the C1 of the subtrahend | 5 − 12 = 00000101 + 11110011 |
| Add in C1 | Bit by bit; the end carry is added to the result | 11111100 + 00000101 → 00000010 |
| Know if it overflows (signed) | Same sign in the addends and another in the result | 0110 + 0011 = 1001 in 4 bits |
Ranges worth knowing
| Bits | Unsigned | Sign-magnitude and C1 |
|---|---|---|
| 4 | 0 … 15 | −7 … +7 |
| 6 | 0 … 63 | −31 … +31 |
| 8 | 0 … 255 | −127 … +127 |
| 16 | 0 … 65535 | −32767 … +32767 |
Templates
Chained addition in C1 (the exam question): translate each number into n-bit binary → C1 of the negatives → first addition (end carry → end-around; impossible sign?) → second addition (the same) → result with its n bits and the overflow box.
Check for any calculation: convert everything to decimal. Division: quotient × divisor + remainder = dividend, with remainder < divisor.
Symptom / probable cause
| Symptom | Probable cause |
|---|---|
| The subtraction gives more than the minuend | A borrow that was not written down |
| The addition has one bit fewer than expected | 1 + 1 + 1 written as 0 with a carry |
| The quotient is much smaller | The zeros of the quotient were skipped |
| In C1 the result is one unit short | The end carry was thrown away instead of added |
| −3 + 5 gives −8 in sign-magnitude | Added bit by bit without looking at the signs |
| «No overflow» and two positives gave a negative | The carry was checked instead of the sign |
Before handing in, ask yourself
- Have I written all the bits asked for (including the zeros on the left)?
- Have I written down the row of carries or borrows?
- In C1, have I given back the end carry?
- Have I checked the result in decimal and looked at the sign to decide on overflow?
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)


