1. Unsigned arithmetic

Unsigned arithmetic

Unsigned addition

We follow the following 4 (bit addition) rules:

Overflow

Take, a -bit value, say . If we perform , we end up at since the addition has overflowed past the MSB.

Hence, this value is discarded and we are left with .

A question may specify a $n$-bit system.
**Always** pick `overflow` if you end with a carry-out, such as above.

Unsigned subtraction

We follow the following 4 (bit subtraction) rules:

Before doing unsigned subtraction, always check the magnitudes of the operands.
For example, $001 - 101$, the second operand is larger than the first, hence since we are working with unsigned binary, this operation is invalid.

Unsigned multiplication

To multiply two binary numbers together:

  1. Select the number with the least digits.
  2. Split the number into parts.
  3. Multiply each part to the other number.
  4. Sum resulting parts.

For example, take .

  • The number we first take is .
  • Split it into and .
  • Take the other number and multiply by the specified power of :
  • Sum the resulting parts: Hence the final answer is .

Unsigned division

Computer systems may opt for short or long division algorithms. Here is an example using long division:

Each comparison should be justified as you progress through each column:

Link to original

2. Signed-magnitude arithmetic

Signed-magnitude arithmetic

Signed addition

Before can before arithmetic with signed-magnitude, we must find and operate on the magnitude as if it was an unsigned binary number.

  • If the signs are the same:
    1. Add magnitude to find resutling mangitude.
    2. Sign bit of result will stay the same.
  • If they’re different:
    1. Subtract smaller magitude from larger magnitude.
    2. Use sign of operand with larger magntiude for result.

Signed subtraction

We can reduce the complexity of computing binary subtraction, such as in , by considering the second operand as a negative number in an addition, by this we can write it as . This is relatively cheap to do, as we only need to flip the sign bit, now we can perform signed-magnitude addition on the two resulting operands.

Signed multiplication / division

  • Multiply or divide magnitudes as signed binary.
  • Check whether both operands have the same sign:
    • If they are the same: result has positive sign.
    • If not: result has negative sign.
Link to original

3. Complement arithmetic

Complement arithmetic

Complement addition

Given 1’s or 2’s complement operands, we can perform the same bit operations as we did with unsigned numbers to find the correct result. Although, at the end, we add the carry-out bit to the final result.

Subtraction

Similarly to signed-magnitude subtraction, we treat the second operand as if it was a negative number. and perform addition instead.

Overflow

Two’s complement overflow occurs when the carry-in to the most-significant bit is not equal to the carry-out.

In this case, the carry-in to the most significant bit is while the carry-out of the MSB is . Hence we’ve experienced an overflow.

In this case, the carry-in to the MSB is the same as the carry-out (). Hence, we just discard the carry-out and get the result .

Complement multiplication / division

We can take one of two approaches:

  • Using a naive approach:
    • Find the magnitude of both operands.
    • Perform the operation as if they were unsigned.
    • Convert result to negative if the operands had different signs.
  • Using a specialised algorithm: Booth’s algorithm for two’s complement multiplication These are not on the exam.
Link to original