'2's complement to signed binary converter using logic gates?

I need to create a 2's complement to signed binary converter using gate circuits. What logic gates can I use?



Solution 1:[1]

You can implement any algorithm using only xor gates I believe. Go for it.

Solution 2:[2]

You can use Not gates to toggle the input bits to get 1's compliment. And then put the output of each Not gate to an input of other "2 input Xor gate".

So if you have N inputs then you need N number of Not gates and N numbers of Xor gates having the output of Not Gates to one of the inputs of Xor gates. And put an 1 (high voltage/low voltage whatever you are using to represent 1) to the another input of the Xor gate where you put the toggled output of least significant input bit. Then put the output of this Xor gate to the second Xor gate, where you put the toggled output of the second least significant input bit. In this way you put the output of the (N-1)th Xor gate output to the input of the Nth Xor gate.

Finally when you take the output form the output of the Xor gates, you will find the 2's complement of the input number.

Solution 3:[3]

Previous answer is partially incorrect. It is correct to use not gates to get 1's complement, but to get the 2's complement you need sum and carry. The sum is performed by XOR gates and the carry is performed by AND gates. Each bit will need an NOT, an XOR and a AND gate. Connect each data line to an NOT gate (performing 1's complement) Connect one input of each XOR to one input of each AND. From now on I will refer this as input1. Connect the other input of each XOR to the other input of each AND. From now on I will refer this as input2. Connect each NOT output to its correspondent input1. Connect the input2 of less significant bit to VCC (logic level 1). Connect the output of less significant AND gate to the input2 of second less significant. (performing carry) Repeat last step for all gates. (cascating the carries) Leave the last AND output unconnected (in fact you do not need that last AND) The 2's complement of your data can be extracted from the output of the XOR gates.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jake Sellers
Solution 2 Sazzadur Rahaman
Solution 3