Two's complement Circuit, how to design?

Discussion in 'Digital Circuit Design' started by kirekhar, Feb 1, 2018.

  1. kirekhar

    Thread Starter New Member

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

    AAC Fanatic!

    Mar 30, 2015
    7,242
    1,682
    How many bits?

    Is this homework?
     
  3. kirekhar

    Thread Starter New Member

    Dec 22, 2017
    11
    0
    N bits :)
    No its not :)
     
  4. WBahn

    Moderator

    Mar 31, 2012
    23,106
    6,951
    So what's the relationship between a number and it's two's complement additive inverse?
     
  5. MrChips

    Moderator

    Oct 2, 2009
    17,133
    5,296
    Why do you want to do this?
     
  6. kirekhar

    Thread Starter New Member

    Dec 22, 2017
    11
    0
    @MrChips Because i want to learn how such things work
     
  7. kirekhar

    Thread Starter New Member

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

    Moderator

    Oct 2, 2009
    17,133
    5,296
    Can you give an example of where you would want to convert a number to its 2's complement?
     
  9. kirekhar

    Thread Starter New Member

    Dec 22, 2017
    11
    0
    @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.
     
  10. MrChips

    Moderator

    Oct 2, 2009
    17,133
    5,296
    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.
     
  11. dl324

    AAC Fanatic!

    Mar 30, 2015
    7,242
    1,682
    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: Feb 1, 2018
  12. panic mode

    Senior Member

    Oct 10, 2011
    1,630
    450
    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
     
  13. kirekhar

    Thread Starter New Member

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

    Thread Starter New Member

    Dec 22, 2017
    11
    0
    @dl324 thanks a lot i will try :)
     
  15. MrChips

    Moderator

    Oct 2, 2009
    17,133
    5,296
    absf likes this.
  16. kirekhar

    Thread Starter New Member

    Dec 22, 2017
    11
    0
  17. MrChips

    Moderator

    Oct 2, 2009
    17,133
    5,296
    You are welcome.
     
  18. WBahn

    Moderator

    Mar 31, 2012
    23,106
    6,951
    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 likes this.
  19. xed_over

    New Member

    Feb 5, 2018
    19
    3
    @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?
     
Loading...