In the previous videos,
we have discussed about binary number representations,
binary number conversions
as well as some complement forms.
Interested viewers can check these videos
on our channel.
We use calculator many a times
opposed to using the page and paper technique
for performing calculations.
Calculator is an electronic device
understanding binary numbers internally.
So how does it perform the complex calculations?
This video discusses how these basic mathematical operations
are performed in binary.
The first mathematical operation presented
is binary addition.
There are some rules laid out to make this task simpler.
These rules dictate the outputs
when certain inputs are added.
Let us understand them.
There are four columns…..
AUGEND,
ADDEND,
SUM
and CARRY.
When both the Augend and Addend are 0,
the Sum and Carry are 0.
When either one of the Augend or Addend is 1,
Sum is 1 and Carry is 0.
When both the Augend and Addend are 1,
Sum is 0 and Carry is 1.
Having studied the rules,
let us solve an example
to actually understand how two numbers
are added in binary.
The numbers added will be 10 and 12.
Their binary representations are
1010
and 1100 respectively.
We know that adding 10 and 12 should produce 22.
The binary numbers are laid out one below the other.
The addition of bits begin with LSB processed first.
The bits 0 and 0 are added
to produce 0 as sum and 0 as carry.
The bits in next column give 1 as sum and 0 as carry.
The next higher column also produces the same result.
The MSB bits 1 and 1 generate
0 as sum and 1 as carry on addition.
This addition gives the result as
10110.
The decimal equivalent of 10110 is 22
which matches with the answer of decimal addition.
The current example only had
two binary numbers to be added.
What if
multiple binary numbers are to be added?
Consider the numbers displayed.
That’s a huge lot of numbers.
The method discussed above can be tedious to process these numbers.
Worry not…
There’s a shortcut to calculate addition of numbers effectively.
If number of 1’s in any column are odd,
sum is
and if 1’s are even, sum is 0.
Every pair of 1 produces a carry
to be added to next higher bits.
This shortcut will make it easier
to calculate the solution to presented problem.
Let us learn about the next mathematical operation
which is binary subtraction.
The rules are as follows.
There are four columns.
Minuend, Subtrahend, Difference and Borrow.
When both Minuend and Subtrahend are same,.
the Difference is 0 and Borrow is 0
When Minuend is 0 and Subtrahend is 1,
the Difference is 1 and the Borrow is 1.
When Minuend is 1 and Subtrahend is 0,
the Difference is 1 and Borrow is 0.
The following example
will help us put these rules into perspective.
We will subtract 0110 from 1010.
Again the first bits to be processed will be LSB.
Performing operation on LSB generates
0 as difference and 0 as borrow.
Moving to next higher column.
Subtracting 1 from 1
gives difference and borrow as 0.
Subtracting 1 from 0 generates
1 as difference and 1 as borrow.
This borrow is reflected in MSB.
In MSB, bit 1 in borrow is also considered.
This operation produces 0 as difference
and 0 as borrow.
The final result obtained is
0100
whose binary equivalent is 4.
If we look at the numbers we subtracted,
they are 10 and 6 which gives 4 in decimal.
This matches the answer generated using bin sub.
For those who are not interested in the conventional way to subtract numbers,
one can perform these
subtractions using rules of addition.
For this 2’s complement representation that we studied in the previous video comes to
our rescue.
This method is called
subtraction using 2’s complement.
It would be easier to understand this method with an example.
Let us sub 6 from 9 and 9 from 6 using this method.
In first case the minuend is 9 and subtrahend is 6.
In 2’s complement method,
the negative number is replaced
by it two’s complement form
and added to other number.
The two’s complement of 6 is 1010.
This binary number is added to 1001.
The addition of these two numbers generate the answer
0011 with carry of 1.
When performing operations using this method,
if carry generated is 1, the carry is discarded
and remaining bits form the actual solution.
In this case,
the remaining bits are 0011
which corresponds to 3 in decimal thereby
giving us the solution.
Let us solve the second case of subtracting 9 from 6.
Here the negative number is 9.
It’s 2’s complement is 0111.
Adding it with 0110 gives 110
as answer with carry of 0.
In this method
if the carry generated is 0,
it denotes that the obtained solution is negative,
and 2’s complement of remaining bits
gives the value of solution.
2’s complement of 1101 is 0011
which equals 3 in decimal.
The carry generated is 0, so the final solution is -3
which matches the answer of 6-9 in decimal.
There are two more basic mathematical operations to be studied in binary.
The multiplication and division.
They will be tackled in the next video.
So subscribe to the channel to stay updated on new videos.
Stay calm and Keep learning.
Peace out.