Secondary Computer Science / 1.3 Working with Fixed-Width Binary

1.3.1 Binary Addition and Overflow

🔒 Lesson slides are available to signed-in users. Sign in

1.3.1 Binary Addition and Overflow

A ticket-counter system stores the number of scanned tickets in an 8-bit register. The register can hold a fixed number of bits, so there is a limit to the largest positive value it can represent.

In this lesson, you will add two positive 8-bit binary integers column by column. You will also learn why an overflow error occurs when the correct mathematical result needs more than eight bits.

By the end of this section, you should be able to:

  • apply the rules for binary addition;
  • add two positive 8-bit binary integers;
  • show carry bits clearly in a binary addition;
  • explain the maximum value stored in an 8-bit positive binary register;
  • identify when an overflow error occurs;
  • explain why overflow happens in fixed-width storage.

Binary addition rules

Binary addition uses the same column method as denary addition: start with the rightmost column and move left. The difference is that each column can only store a binary digit: 0 or 1.

Binary addition 二进制加法: adding binary values using columns and carry bits.

Carry 进位: a value passed to the next column when a column result is too large to fit in the current column.

Least significant bit 最低有效位: the rightmost bit, with the smallest place value.
Column addition Write in this column Carry to next column
0 + 0 0 0
0 + 1 1 0
1 + 0 1 0
1 + 1 0 1
1 + 1 + carried 1 1 1

Common mistake

In binary, 1 + 1 is written as 10. This means write 0 in the current column and carry 1 to the next column.

The column method

When adding two 8-bit binary integers, keep all eight bit positions aligned. Work from right to left and include any carry from the previous column.

8-bit binary integer 八位二进制整数: a binary integer represented using exactly eight bit positions.

Register 寄存器: a small storage location inside the processor. In this lesson, the register has space for eight bits.
Step Action Reason
1 Write both 8-bit values in columns Each bit must stay in the correct place-value position
2 Start at the rightmost bit This is the least significant bit
3 Add the two bits and any carry-in The current column may already have a carried value
4 Write the result bit Only one bit can be stored in the current column
5 Carry 1 left if needed The next column must include the carried value

Answer-building tip

Show the carry row above the addition. It makes your working easier to check and helps avoid losing a carry between columns.

Worked example: addition with no overflow

Add the following two positive 8-bit binary integers:

01011001 + 00100111

Step 1: align the values

  01011001
+ 00100111
----------

Step 2: work from right to left

Column place value Addition in the column Result bit Carry left
1 1 + 1 = 10 0 1
2 0 + 1 + carry 1 = 10 0 1
4 0 + 1 + carry 1 = 10 0 1
8 1 + 0 + carry 1 = 10 0 1
16 1 + 0 + carry 1 = 10 0 1
32 0 + 1 + carry 1 = 10 0 1
64 1 + 0 + carry 1 = 10 0 1
128 0 + 0 + carry 1 = 1 1 0

Step 3: write the final 8-bit result

  01011001
+ 00100111
----------
  10000000

Step 4: check in denary

89 + 39 = 128

The result 10000000 is still an 8-bit value, so no overflow occurs.

The limit of an 8-bit positive register

An 8-bit register has exactly eight bit positions. For positive binary values, the largest value occurs when every bit is 1.

8-bit pattern Selected place values Denary value
11111111 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 255
Fixed width 固定位宽: a representation that always uses a fixed number of bit positions.

Maximum value 最大值: the largest value that can be represented using the available bit positions.

For an 8-bit positive binary integer, any mathematical result greater than 255 cannot fit into the register.

Common mistake

Do not say that an 8-bit register stores every positive whole number. It can only represent values from 0 to 255 in this positive-integer context.

Overflow

Overflow occurs when the result that should be returned is outside the range that can be represented using the available number of bits.

Overflow 溢出: an error condition that occurs when a result is too large to fit into the available storage width.

Overflow error 溢出错误: the error produced when the required result is outside the representable range.

In this lesson, the register has eight bits. The largest positive value is 255. Therefore, overflow occurs if the addition result is greater than 255.

Answer-building tip

A clear explanation should include the limit: overflow occurs because the result is greater than 255, so it cannot be represented in an 8-bit positive binary register.

Worked example: addition with overflow

Add the following two positive 8-bit binary integers:

11101010 + 00011101

Step 1: check the denary values

11101010 = 234, and 00011101 = 29

234 + 29 = 263

Since 263 is greater than 255, the result cannot fit into an 8-bit positive register.

Step 2: add the binary values

  11101010
+ 00011101
----------
1 00000111

The correct mathematical result needs nine bits: 100000111. An 8-bit register has no space for the extra carry on the left.

Step 3: identify the overflow

If only the lower eight bits were kept, the stored pattern would be 00000111, which represents 7. That is not the correct result of 234 + 29.

Common mistake

The lower eight bits are not the correct answer when overflow occurs. The important conclusion is that the result is too large for the 8-bit register.

Carry and overflow are connected, but not identical

A carry can occur inside the calculation without causing overflow. Overflow happens only when the final result cannot fit into the available number of bits.

Situation Example Overflow? Reason
Carry between middle columns 01011001 + 00100111 = 10000000 No The final value 128 fits in 8 bits
Final carry out of the leftmost bit 11101010 + 00011101 = 1 00000111 Yes The value 263 needs more than 8 bits

Use precise language

Say “a final carry out of the 8-bit register shows that the positive result is too large to store”, rather than simply saying “there was a carry”.

Interactive: 8-bit Binary Addition Laboratory

Enter two positive 8-bit binary integers. The laboratory adds them from right to left, shows each carry, and reports whether the result fits in an 8-bit register.

Interactive investigation

Add two positive 8-bit binary integers

8-bit result 10000000 No overflow
Denary: 89
Denary: 39
Press “Animate columns” to inspect the addition step by step.

Column working

First value 89
Second value 39
Mathematical sum 128
8-bit limit 255
Overflow check 128 fits in an 8-bit positive register, so no overflow occurs.

Overflow challenge

Predict before adding

Will 11001100 + 00110110 cause overflow?

Choose an answer.

Think before calculating

In 8-bit positive addition, a quick denary check is useful: if the two values add to more than 255, overflow must occur.

Practice

Core questions

  1. State the result of 1 + 1 in binary addition.
  2. Explain the purpose of a carry bit.
  3. Add the following positive 8-bit binary integers: 00110110 + 00011001.
  4. Add the following positive 8-bit binary integers: 01001111 + 00100010.
  5. Add the following positive 8-bit binary integers: 01110001 + 00011110.
  6. State the largest positive denary value that can fit in an 8-bit register.
  7. Define the term overflow.
  8. Explain why 11110000 + 00110000 causes overflow in an 8-bit positive register.
  9. A student gets the result 00000101 from an addition but ignores a final carry out of the leftmost bit. Explain why this is not a valid 8-bit positive result.
  10. Explain the difference between a carry inside the calculation and an overflow error.

Extension questions

  1. Add 10110110 + 01001001. State whether overflow occurs and justify your answer.
  2. Create two different pairs of positive 8-bit binary values that add to 255.
  3. A small device stores a counter in an 8-bit positive register. Explain what could happen if the counter is increased after it already contains 255.
  4. Explain why the concept of a predefined storage limit is important in binary addition.
Check selected answers
  1. 1 + 1 gives 10, so write 0 and carry 1.
  2. 00110110 + 00011001 = 01001111.
  3. 01001111 + 00100010 = 01110001.
  4. 01110001 + 00011110 = 10001111.
  5. The largest 8-bit positive value is 255.
  6. 11110000 + 00110000 = 1 00100000, so overflow occurs.
  7. 10110110 + 01001001 = 0 11111111 with a final carry, so overflow occurs because the denary sum is 255? Check carefully: 182 + 73 = 255, so no overflow occurs and the result is 11111111.

Review

Key ideas

  • Binary addition is performed from right to left.
  • 1 + 1 gives 10, so 0 is written and 1 is carried.
  • A carry may be passed from one column to the next.
  • Two positive 8-bit binary integers must be aligned in eight columns.
  • The largest positive value in an 8-bit register is 255.
  • Overflow occurs when the required result is outside the available range.
  • For 8-bit positive addition, overflow occurs when the result is greater than 255.
  • A final carry out of the 8-bit register means the result cannot be stored in eight bits.

Quick self-check

  1. Can I apply the binary addition rules correctly?
  2. Can I show carry bits in a column addition?
  3. Can I add two positive 8-bit binary integers?
  4. Can I explain why an 8-bit positive register has a limit of 255?
  5. Can I identify and explain overflow?

One-minute exit task

Add 10010101 + 01101110. State whether overflow occurs and explain your reason.