I have to subtract two binary numbers, each two bits long.
so the numbers are x0x1 and y0y1. the result z0z1 has to be the absolute value.
At my disposal are: a two bit subtractor (ie it subtracts two numbers of two bits each and puts out two bits which is the result)
I also have a magnitude comparator for two number each two bits.
The magnitude comparator has three outputs:
x > y, x = y, x < y
I also have 4 xor gates.
I figured the best way to approach this problem is to let the subtractor do the subtraction and if y0y1 > x0x1 then swap the inputs to the subtractor.
I'm thinking that I have to somehow use the 4 xor gates and the magnitude comparator to do the switching if the case above is true. but I can't figure out how.
Best Answer
Here's the schematic I'd been discussing:
simulate this circuit – Schematic created using CircuitLab
It was just a matter of inverting the inputs, based upon the comparison output.
It's a little excessive to do it that way, but also pretty obvious when you think about it. (I gather those were the parts you are given to work with.)
A simplification isn't too difficult:
simulate this circuit
But it is a little bit less obvious, until you look at the algebra (or table.)