views:

121

answers:

4

Basically I have 2 unsigned 8-bit binary numbers and I need to use Boolean logic to find out which is larger and I can't for the life of me figure out where to start. Using Logic gates...

Obivously I have to analyse each bit and find out which one is larger but how do I bring it all together?

Say I had x and y and wanted to return true if x < y (x and y are 8bit unsigned binary numbers). How would I go about doing this?

I thought about finding which has the most significant bit, but what if they are both the same?

Anyone got any ideas?

+1  A: 

I thought about finding which has the most significant bit, but what if they are both the same?

You proceed from "most significant bit" down to the "least significant bit" until there is a difference. The number with the first bit set to "1" is greatest.

To implement this, use a "shift register" for each number and a comparator for the bits "out" of the SR.

jldupont
How do I then latch out of my recursive function which checks whether one is bigger than the other?
Ben
You would use a normal "register" (probably not a "latch" in this case) with a very simple state-machine.
jldupont
A: 

You're part way there. Yes, start from the most significant bit. If they are both the same, move to the next bit (moving right, towards the least-significant bit). When you find a bit that is set (and the other isn't), that is the greater number.

Robert Cartaino
A: 

Indeed, you're on the right track. First compare the most significant bit. If they are not equal, you can already output the result, one way or the other. If they are equal, then you just output the result of comparing the second most significant bit. And so on until the least significant bit. Recursion in a way. In the result you will have the same configuration of gates repeated for each bit, except for the last one which will have a slight variation (because there is no further bit after that one).

Vilx-
A: 

If the high bit of one is "bigger" (ie: it's 1 and the other one is 0), then than number is the bigger one.

If they're the same then perform the same test on the next bit.

So you want something like this C-like pseudo-code (pretending that we have the bits in arrays with the most significant in the 0 position):

// true iff x > y
(x[0] == 1 && y[0] == 0) 
|| (
  (y[0] == x[0]) 
  && (the entire expression all over again, but with [n+1] instead of [n])
)

For your base case (ie: when there are no more bits to test), use false or true depending on whether you want > or >=.

Laurence Gonsalves