Be able to:
- add two unsigned binary integers
- multiply two unsigned binary integers.
Adding two binary integers is similar to adding two positive decimal integers. Each bit is added in turn starting from the right most bit (least significant) and continuing to the most significant bit (MSB).
- When two bits are both
0
, the sum is 0. - When one of the bits is
1
and the other is0
then the sum is1
. - When both bits are
1
then you must carry a1
into the next bit's sum and then place a0
in the current bit
Example
1 0 0 0 1 1 0 1
+ 0 1 1 0 1 0 0 0
1 0 0 0 1 1 0 1
+ 0 1 1 0 1 0 0 0
-----------------------
Sum: 1 1 1 0 0 1 0 1
Carry: 1
Total: 1 1 1 1 0 1 0 1
Binary multiplication is very simple. To multiply two binary integers you sum the values of shifting the first number by every 1 in the second number. It is similar to decimal multiplication.
- When multiplying by a 0 bit the value is all 0's
- When multiplying by a 1 bit, the value is the original number shifted by the number of bit up to the 1 bit
- Remember to sum all the numbers at the end
Example
1 0 0 0 1 1 0 1
X 0 0 0 0 1 0 0 1
1 0 0 0 1 1 0 1
x 0 0 0 0 1 0 0 1
--------------------------
1 0 0 0 1 1 0 1
1 0 0 0 1 1 0 1 0 0 0 0
--------------------------
1 0 0 1 0 1 0 1 1 1 0 1