Takes two input vectors (so, like, one or more bits) A and B, and determines if A is less than, greater than, or equal to B.
There are 4 total permutations for 1-bit inputs, which makes 1 bit comparators super easy!

But for more than 1 bit, things get spicy.
- For instance if weβre talking about 2 bit inputs, A == B only when and so that becomes obtuse quite fast

- To check if A is greater than B we check if
- . In that case, is a given, or
- This looks like
- and .
- This looks like
less than is similar!

- This looks like
less than is similar!
- . In that case, is a given, or
The expression is true when the first bit is equal (replace the 1βs with 0βs to get when the second bit is equal)
General comparators
For a βgeneralβ comparator we need to define some things:
Equality:
- For equality of any bit, we have
- That gives us
> and <
- For any digit, if the previous are equal, and the one weβre on, satisfies:
- and , then no matter what bits after follow it
- and , then for similar reason to above
- That gives us, for any sized input stream:
-
- The first check is your base case (if the first bit of A is bigger than the second of B, then boom youβre done)
- the is defined from before
- The second checks if the bits before are equal. if they are, we also compare the bit at.
- This repeats until weβre checking for every bit before the last bit; if theyβre all equal, then compare the bits weβre at.
- The first check is your base case (if the first bit of A is bigger than the second of B, then boom youβre done)
- The same is reflected on of course
-
Example of 4-bit comparator expressions
Subtraction instead
The more bits you have, the more complex comparing becomes. Therefore, subtracting might be the play. Simply subtract A and B, and if the sign changes, you can determine if A < B or A > B!
