Comparators
A comparator takes two binary inputs (A and B) and compares them. One of three outputs is generated: A = B, A > B, or A < B.
A onebit comparator satisfies these three Boolean equations:
A = B 

A > B 

A < B 
The following circuit satisfies the requirements for a onebit comparator:
It is possible to cascade onebit comparators to compare larger numbers; however, as the number of input bits increases the comparator's logic becomes more complex. As with most circuits, it is easier to use an IC to do this job rather than attempt to create a comparator from discreet gates. Following is a functional logic diagram for the 74F85 4bit comparator. NOTE: this diagram is intended to show the logic function of the 74F85, it is not an accurate representation of the pinout on a physical IC.
This device takes two 4bit inputs and compares them. The appropriate output goes high while the others stay low. For example, if A = B then output A = B will be high while A < B and A > B will be low, as illustrated. Additionally, this IC can input the result of a previous comparison (the three input terminals in the center are labeled A < B, A = B, and A > B) so these ICs can be cascaded to create a comparator for binary numbers greater than 4bits. NOTE: The 74F85 IC is designed in such a way that a constant high (or 1) must be present on the A=B input in order for the circuit to function; the two other inputs have been tied to ground (a constant 0) in order to keep them from floating.
To create an 8bit comparator, two 74F85 ICs are cascaded. The four low order bits are fed into the first IC and the four high order bits are fed into the second IC: