Binary Arithmetic and Shifts
Binary Addition
Adding two binary numbers follows four simple rules. Applying these column by column from right to left gives the result:
- 0 + 0 = 0
- 1 + 0 = 1
- 1 + 1 = 10 (write 0, carry 1)
- 1 + 1 + 1 (carry) = 11 (write 1, carry 1)
The carry bit moves one column to the left, just as it does in denary addition. Always work right to left, recording each sum digit and carrying any overflow to the next column.
Add 01101100 (108) and 00110101 (53):
01101100 + 00110101 ----------
Working right to left:
Col 1 (1s): 0+1 = 1
Col 2 (2s): 0+0 = 0
Col 3 (4s): 1+1 = 0, carry 1
Col 4 (8s): 1+0+carry1 = 0, carry 1
Col 5 (16s): 0+1+carry1 = 0, carry 1
Col 6 (32s): 1+1+carry1 = 1, carry 1
Col 7 (64s): 1+0+carry1 = 0, carry 1
Col 8 (128s): 0+0+carry1 = 1
Result: 10100001
Check: 108 + 53 = 161; 10100001 = 128 + 32 + 1 = 161 ✓
Binary addition rules: 0+0=0; 1+0=1; 1+1=0 carry 1; 1+1+1(carry)=1 carry 1. Always work right to left. Show the carry row clearly in your working — visible carries earn method marks.
Overflow
Overflow happens when the result of an addition exceeds the maximum value that can be stored in the available bit width. For 8-bit unsigned arithmetic, the maximum storable value is 255. If the addition produces a carry out from the leftmost (most significant) bit, the result cannot fit in 8 bits and overflow has occurred.
For example, adding 11000000 (192) and 01000001 (65) produces a carry beyond the 8th bit. The 8-bit result is incorrect — the true total of 257 cannot be stored in 8 bits. In a real computer, this causes an error state or silent data corruption depending on the hardware design.
Overflow occurs when an arithmetic result is too large for the number of bits available. In 8-bit unsigned addition, overflow happens when the true result exceeds 255 — a carry bit is produced beyond the eighth bit position and the stored result is incorrect.
Binary Shifts — Logical and Arithmetic
A binary shift moves every bit a stated number of positions left or right. There are two types: logical and arithmetic. Both left-shift by the same rules, but they differ when shifting right.
Logical Shifts
In a logical shift, every vacated bit position is filled with 0. A logical left shift by 1 moves every bit one place to the left, fills the rightmost position with 0, and loses the leftmost bit. A logical right shift by 1 moves every bit one place to the right, fills the leftmost position with 0, and loses the rightmost bit.
Effect on value: a logical left shift by \(n\) places multiplies the number by \(2^n\). A logical right shift by \(n\) places divides the number by \(2^n\) (integer division — remainder is lost). Example: 00001100 (12) logical-left-shifted by 2 gives 00110000 = 48. Check: \(12 \times 4 = 48\) ✓.
Arithmetic Shifts
An arithmetic shift is designed for use with two’s complement signed numbers. The key difference from a logical shift is in a right arithmetic shift: the sign bit (the most significant bit) is preserved — the vacated position on the left is filled with a copy of the sign bit, not with 0.
An arithmetic left shift works identically to a logical left shift — vacated positions are filled with 0. For positive numbers (where the sign bit is 0), an arithmetic right shift and a logical right shift produce the same result. The difference only appears for negative numbers, where the sign bit is 1.
Start with the 8-bit pattern 11110000. As a two’s complement signed integer: −128 + 64 + 32 + 16 = −16.
Logical right shift by 2:
Vacated positions filled with 0: 00111100
Denary value: 32 + 16 + 8 + 4 = 60
Result is now positive — the sign has changed. The logical shift ignores the sign bit and treats the pattern as unsigned.
Arithmetic right shift by 2:
Sign bit is 1, so vacated positions on the left are filled with 1: 11111100
Denary value: −128 + 64 + 32 + 16 + 8 + 4 = −4
Check: −16 ÷ 4 = −4 ✓. The arithmetic shift preserves the sign and correctly divides the signed value by \(2^2\).
Logical right shift: always fills vacated positions with 0. Treats the number as unsigned. Arithmetic right shift: fills vacated positions with a copy of the sign bit (0 for positive, 1 for negative). Preserves the sign of two’s complement numbers. Both left shifts work the same way — filling with 0.