Take, a 3-bit value, say 111.
If we perform 111+001, we end up at 000 since the addition has overflowed past the MSB.
111+0011000
Hence, this 1 value is discarded and we are left with 000.
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:
0−0=0
1−0=1
1−1=0
0−1=borrow
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:
Select the number with the least 1 digits.
Split the number into parts.
101⇒100 and 001
Multiply each part to the other number.
Sum resulting parts.
For example, take 01111×10010.
The number we first take is 10010.
Split it into 10000 and 00010.
Take the other number 01111 and multiply by the specified power of 2:
01111×10000=01111<<4=011110000
01111×00010=01111<<1=000011110
Sum the resulting parts:
011110000+0000111100100001110
Hence the final answer is 0100001110.
Unsigned division
Computer systems may opt for short or long division algorithms.
Here is an example using long division:
0010012101)101101−1010101−1010
Each comparison should be justified as you progress through each column:
110101110101<1012<1012≥1012<1012<1012≥1012Link 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:
Add magnitude to find resutling mangitude.
Sign bit of result will stay the same.
If they’re different:
Subtract smaller magitude from larger magnitude.
Use sign of operand with larger magntiude for result.
Signed subtraction
We can reduce the complexity of computing binary subtraction, such as in a−b, by considering the second operand as a negative number in an addition, by this we can write it as a+(−b).
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.
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.
010100+1101001001010+1001011
Subtraction
Similarly to signed-magnitude subtraction, we treat the second operand as if it was a negative number. a−b=a+(−b) 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.
01101+0010010001
In this case, the carry-in to the most significant bit is 1 while the carry-out of the MSB is 0. Hence we’ve experienced an overflow.
01101+10110100011
In this case, the carry-in to the MSB is the same as the carry-out (1). Hence, we just discard the carry-out and get the result 00011.
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.