Module 1: Foundations of Digital Logic · 1.1 Number Systems & Arithmetic

Binary Addition, Subtraction, and Arithmetic Overflow

Digital Arithmetic Logic Units (ALUs) execute arithmetic operations using binary adders. This article explains multi-bit addition, two’s complement subtraction, arithmetic overflow detection, and fixed-point representations.

Binary Column Addition

Binary addition operates on positional columns using base-2 addition rules. When the sum of a column equals or exceeds 2, the circuit generates a carry bit to the adjacent higher-order column.

A single bit-position adder evaluates three inputs: operand bit A, operand bit B, and carry-in ($C_{in}$). It generates two outputs: Sum ($S$) and carry-out ($C_{out}$).

Operand A Operand B Carry In ($C_{in}$) Sum ($S$) Carry Out ($C_{out}$)
0 0 0 0 0
0 1 0 1 0
1 0 0 1 0
1 1 0 0 1
0 0 1 1 0
0 1 1 0 1
1 0 1 0 1
1 1 1 1 1

In base-2 addition, $1_2 + 1_2 = 10_2$ (Sum = 0, Carry Out = 1).

Example: Add 4-bit values +5 and +3:

  Carry:  0110
          0101   (+5)
        + 0011   (+3)
        ------
          1000   (+8)
  1. Bit position 0: $1 + 1 = 0$, carry = 1.
  2. Bit position 1: $0 + 1 + 1 = 0$, carry = 1.
  3. Bit position 2: $1 + 0 + 1 = 0$, carry = 1.
  4. Bit position 3: $0 + 0 + 1 = 1$, carry = 0.

The sum is $1000_2$ (decimal 8).

Example: Add 4-bit unsigned values 10 and 7:

  Carry:  1110
          1010   (10)
        + 0111   (7)
        ------
        1 0001

The mathematical result is 17 ($10001_2$). The 4-bit output bus stores 0001 (decimal 1). The fifth bit generates a carry-out signal, which indicates that the result exceeds register capacity.

Hardware Subtraction

Digital processors do not require separate subtraction circuits. To calculate $A - B$, the ALU executes addition using the two’s complement of operand B:

$$A - B = A + (\sim B + 1)$$

Example: Calculate $9 - 5$ using an 8-bit adder.

Decimal +9 is 00001001. Decimal +5 is 00000101. Invert all bits of +5 (11111010) and add 1 to obtain −5 (11111011):

  Carry:  11111000
          00001001   (+9)
        + 11111011   (-5)
        ----------
        1 00000100

Discard the final carry-out bit. The resulting 8-bit value is 00000100 (decimal +4).

To execute subtraction, the control logic asserts invert gates on operand input B and asserts carry-in $C_{in} = 1$ on the least significant bit. This configuration executes subtraction using an unmodified binary adder.

Arithmetic Overflow Detection

Arithmetic overflow occurs when a computational result exceeds the representable numerical range of the output register. Processors track two distinct overflow conditions: unsigned overflow and signed overflow.

Unsigned Overflow and the Carry Flag

In unsigned arithmetic, overflow occurs when an addition operation generates a carry-out bit from the most significant bit ($C_{out} = 1$).

  Carry:  1111
          1111   (15)
        + 0001   (1)
        ------
        1 0000

The true sum is 16, which exceeds the 4-bit unsigned range (0 to 15). The ALU sets the Carry Flag (C) in the processor status register.

Signed Overflow and the Overflow Flag

In two’s complement arithmetic, a carry-out from the MSB does not indicate an error. Signed overflow occurs when an operation generates a result that violates sign integrity:

  • Adding two positive operands produces a negative result.
  • Adding two negative operands produces a positive result.

Hardware detects signed overflow by evaluating the carry into the sign bit ($C_{in,MSB}$) and the carry out of the sign bit ($C_{out,MSB}$):

$$V = C_{in,MSB} \oplus C_{out,MSB}$$

When these two carry signals differ, the ALU sets the Overflow Flag (V).

Example: Add signed 4-bit values +7 and +1:

  Carry:  0111
          0111   (+7)
        + 0001   (+1)
        ------
          1000   (-8 in two's complement)

The carry into bit 3 is 1. The carry out of bit 3 is 0. Because $1 \oplus 0 = 1$, signed overflow occurs. The mathematical sum (+8) exceeds the positive limit of a 4-bit signed register (+7).

Note: Adding operands with opposite signs cannot cause signed overflow, because the magnitude of the sum is always less than the largest input operand.

Adder Topologies: Ripple-Carry versus Carry-Lookahead

In a ripple-carry adder, each full adder stage must wait for the carry-out signal from the preceding bit stage. The carry signal propagates sequentially from the LSB to the MSB. In 32-bit and 64-bit ALUs, this propagation delay limits maximum clock frequency.

A carry-lookahead adder calculates carry signals across multiple bit positions simultaneously using parallel combinational logic. This architecture reduces propagation delay at the expense of higher gate count and power consumption.

Fixed-Point Fractional Numbers

Fixed-point notation represents fractional numbers without dedicated floating-point units. The designer assigns a fixed number of bits to the integer component and the remaining bits to the fractional component.

In a Q4.4 format, a byte contains four integer bits and four fractional bits:

$$b_3 b_2 b_1 b_0 ,., f_{-1} f_{-2} f_{-3} f_{-4}$$

The fractional bit weights correspond to negative powers of two:

  • $f_{-1} = 2^{-1} = 0.5$
  • $f_{-2} = 2^{-2} = 0.25$
  • $f_{-3} = 2^{-3} = 0.125$
  • $f_{-4} = 2^{-4} = 0.0625$

Example: Represent decimal 6.75 in Q4.4 format:

  • Integer component: $6_{10} = 0110_2$
  • Fractional component: $0.75_{10} = 0.5 + 0.25 = 1100_2$
  • Result: 0110.1100

Standard binary integer adders process fixed-point additions directly without architecture modification, provided both operands maintain matching fractional bit alignments.

Practice Exercises

  1. Compute $13 - 6$ in 8-bit two’s complement representation.
  2. Add signed 8-bit values 01100100 (+100) and 00101000 (+40). Determine if signed overflow or unsigned overflow occurs.
  3. Express decimal value 2.375 in Q4.4 fixed-point format.
View Solutions
  1. Binary +13 is 00001101. Binary +6 is 00000110. Negate +6 to obtain −6 (11111010). Adding 00001101 and 11111010 yields 1 00000111. Discarding the carry bit produces 00000111 (decimal +7).
  2. The binary sum is 10001100. Two positive numbers produced an MSB of 1 (negative). Signed overflow occurred because the sum (140) exceeds the signed 8-bit limit (+127). The carry out of the MSB is 0, so unsigned overflow did not occur.
  3. Decimal 2 is 0010. The fraction $0.375 = 0.25 + 0.125$ is 0110. The Q4.4 representation is 0010.0110.
← Negative Numbers in Hardware: Two's Complement Boolean Algebra: Two Values, Three Operations →