Two's complement Circuit, how to design?

Thread Starter

kirekhar

Joined Dec 22, 2017
11
I wanted to create a Circuit for inverting Numbers in Two's complement with nand nor and inverters
Can anyone help me ?
 

WBahn

Joined Mar 31, 2012
24,684
So what's the relationship between a number and it's two's complement additive inverse?
 

Thread Starter

kirekhar

Joined Dec 22, 2017
11
@WBahn What do you mean ? I know how to convert it "manually" but how can i realize it in a circuit ?
 

Thread Starter

kirekhar

Joined Dec 22, 2017
11
@MrChips If you dont want to help, it doesnt matter, you dont have to
I just wanted to make a challenge for myself and understand how i would make a circuit of this topic.
But i dont know the answer, so i asked.
 

MrChips

Joined Oct 2, 2009
19,270
@MrChips If you dont want to help, it doesnt matter, you dont have to
I just wanted to make a challenge for myself and understand how i would make a circuit of this topic.
But i dont know the answer, so i asked.
You misunderstand. I am here to help you.
What you have not indicated is where would anyone use such a circuit.
The reason for asking is that perhaps you do not understand its application or lack of application.
 

dl324

Joined Mar 30, 2015
8,869
But i dont know the answer, so i asked.
If it was a fixed number of bits, you could just make a truth table.

For a variable number of bits, I'd make a circuit that handled one bit and cascade as many as you need.

EDIT:
I designed the circuit and cascaded for 4 bits. I blocked out the logic so you can do it yourself.
upload_2018-2-1_10-11-49.png

EDIT 2:
If the picture confuses you, I made carry in and carry out low active. It allowed me to simplify the logic a bit. In my rush, I didn't negate the Ci/Co labels.
 
Last edited:

panic mode

Joined Oct 10, 2011
1,782
whatever your word length is, invert all bits (for N bits you need N inverters).
also there will be an adder in there.... lookup halfadder logic
 

Thread Starter

kirekhar

Joined Dec 22, 2017
11
@MrChips Okay sorry for missunderstanding you :)
Its just because im a bit bored and wanted to do something with my time, nothing special
 

WBahn

Joined Mar 31, 2012
24,684
@WBahn What do you mean ? I know how to convert it "manually" but how can i realize it in a circuit ?
If you know how to do something manually, then that is usually a good first step in figuring out a circuit to do it.

List the steps that you would follow to do it my hand.

Then see which of those steps you can implement in logic.

The ones that you can't are the ones that you need to focus on, but now you are focusing on smaller problems, which are usually easier to figure out.

You might also start by listing as many different ways of doing it by hand that you can think of. While circuit implementations of any of them would be valid, some might be much easier to implement than others.

There's also the question of why you are wanting to do this to begin with. If it's purely for learning purposes, that's fine. But if you have an application in mind, it is very possible that the same goal can be achieved using a different and simpler approach. I was designing a chip once and needed to subtract a value from another one. The first thought was to use two's complement. But after looking at things for a few hours I realized that if I used one's complement that I could significantly reduce the circuit size and improve the speed considerably because I just didn't need the nice things that two's complement brought to the table.
 

xed_over

Joined Feb 5, 2018
19
@kirekhar , a little Googling can easily show how to do this, but like the other's are alluding, its not clear that you understand what you're asking. Since two's complement generates a negative of the input, why do you want to merely display the negative of a given number? I guess a a calculator has the function to merely negate a number and display it.

Ok, so what is two's complement? Its merely one's complement plus add one to it.
What is one's complement? Its just invert the input. NOT gates on each bit will do that.
But figuring out how to add one is actually the harder part. Now you need to implement half/full adder circuits for each bit to do that (half adder has no carry-in).

Do you know what to do now?
 
Top