Modelling priority/importance in a digital circuit

digital-logic

I'm attempting to create a digital circuit that has three inputs representing binary numbers. For example 001 would equal 1 in decimal , 011 would equal 3 and 111 would equal 7. So overall the highest number you can make is 7.

I have been designing a circuit that compares two of these sets of 3 numbers and I have realised that what I'm actually doing is comparing sets of 3 inputs, rather than looking at the numerical values 0-7. What this meant for me in practice was that my circuit output whichever set contained more 1's so that 101 would equal 110 because they both have 2 1's when in fact they are two different numbers when we convert it to binary.

I was wondering if anyone could tell me how to go about modelling the binary logic within my system so that I can be comparing numbers from 0-7 rather than sets of 1's.

Best Answer

I understand you want to find out which of the two numbers is larger? You can do that by comparing the bits of A and B, starting at the highest ones, let's call those A3 and B3.

There are three cases: they are equal, or otherwise A3 is 1 (and B3 is 0), or B3 is 1 (and A3 is zero). In the first case (equal), which one is larger is determined by the next (lower) bit. If they are not equal, take the A3 bit and it tells you whether A is larger. So for the left most bit:

A_is_larger = ( ( A3 == B3 ) * ( input from lower bits ) ) + ( ( A3 != B3 ) * A3 ).

For the rightmost bit the you can simplify this to A1 (assuming that for equal values you don't care what the outcome is).

Related Topic