Basics of Digital Electronics Part 4

 Binary Subtraction


        As you learnt in the 3rd Part that how binary addition is done inside the computer or microprocessor using the logic gates. In this part we will discuss how binary subtraction is performed using these gates. First of all I will explain two terms : 1's Complement and 2's Complement

1's Complement:

                             1's complement is made by inverting all the bits or simply we can say by changing all the 1's to 0 and all the 0's to 1. For example we have a value 1010 and its 1's complement will be 0101.

2's Complement:    

                            2's complement is made simply by adding 1 to 1's complement. 2's complement of 1010 will 0110 (0101+1).

     
           Now we will discuss how subtraction is done. Suppose we have a value A =1111 and B=0111.
Then subtraction of two values A-B will be 1000.

                                                                           1 1 1 1
                                                                       -  0 1 1 1
                                                                       _______
                                                                          1 0 0 0

          Now take 1's complement of B (0111) which will be equal to 1000 and then take 2's complement and it will be 1001. If we add 2's Complement of B with A then the result will be 11000 which will be equal to subtraction of A and B  (1000) after discarding the carry.

            But the question is how it can be implemented using logic gates?

            First take a look on the truth table of XOR gate.

       


            In the above table when input A is 0 then Output of the XOR gate is same as the Input B but when Input A is 1 then Output is not of B or 1's complement of B. Simply we can say that XOR gate is a controlled inverter. When A is 0 then it gives the output without inverting B and if A is 1 it gives the inverted output or it gives the 1's complement.

         IC 7486 contains the 4 XOR gates in a single pack. Now we will use it to perform subtraction. Pin diagram of IC is shown below.




          The circuit for performing the subtraction is shown below. In this circuit IC 7483 is used as an adder as discussed in the 3rd Part . 






           IC 7486 contains 4 XOR gates and A inputs of these gates and Cin of adder is connected together as shown in the image.

 Operation:

                  Suppose we have two quantities A= 1111 and B=0111 . A is given directly to the adder and B is given through the XOR gates. When A inputs of XOR gates and Cin of the adder is connected to 0 then output of the XOR gates is same as input B and Cin is also 0 so the result will be equal to the addition of A and B.

                                                                              1 1 1 1
                                                                        +   0 1 1 1
                                                                        +            0
                                                                        __________
                                                                           1 0 1 1 0

                 When Inputs of XOR gates and Cin is connected to 1 then XOR gates invert the input B and adder adds the A and 1's Complement of B and Cin.


                                                                          1  1  1  1
                                                                       + 1 0 0 0
                                                                       +           1
                                                                       _________
                                                                        1 1 0 0 0

            After discarding the carry out the result is equal to the subtraction of A and B (1000).
This is how binary subtraction is performed by the computer or microprocessor.

Next Part : Flip Flops




         



          

Comments

Popular Posts