how to automatically switch between adder and subtractor

Discussion in 'The Projects Forum' started by miketest, Sep 9, 2013.

  1. miketest

    Thread Starter New Member

    Nov 9, 2012
    So basically I'm working on a project that's supposed to emulate a betting game about randomly generated numbers... the idea was that if your number is higher than the number of another player, you win.... so I thought that to make that circuit, I would just use a subtractor(using 2's complement)... anyways the win would be decided if there would still be an overflow bit left or not....

    I would then use that overflow bit in our next step... the thing was that if I had a stored value, winnings, and also another inputted value, the bet, a new logic circuit would then either add or subtract the two... here's the problem: how the I use the overflow bit to dictate whether the circuit would subtract or add the winnings and the bet.

    What I tried doing was doing the 2's complement again... if the overflow bit was a 1, it would convert the bet into a 2's complement form.. However, I cannot do that effectively at all.... So if you actually read the whole thing, helpful suggestions on how to implement this circuit would be very welcome...

    note: i think a multiplexer could be just the solution but I'm having trouble visualizing that too. and not to mention that it's not available to us as it was not discussed in our laboratory syllabus
  2. JohnInTX


    Jun 26, 2012
    You can route the bits of the subtrahend/addend through 2 input XOR gates (one bit per gate) with the overflow common to the other inputs. When the overflow is '1', the outputs of the XORs will form the 1s compliment of the number (when '0', no inversion - for adding). Run the XOR outputs into full adders with the overflow being the carry in to add '1' to the complement/subtract result. Now when overflow is 1, the 2s comp subtraction is performed, when 0, addition is performed. Clock the adder's output into the result register.

    There are surely other, better ways but I'm still on the first cup of coffee.

    Or use a 74181?
    Last edited: Sep 9, 2013
  3. miketest

    Thread Starter New Member

    Nov 9, 2012
    wow thanks.... can't believe it could have been that simple... thanks a lot
  4. crutschow


    Mar 14, 2008
    How about using a digital comparator such as the CD4063? It has an equal-to, less-than, and more-than outputs for two digital binary number inputs.
    djsfantasi likes this.