Consider two 4-bit binary numbers A and B so
A = A 3 A 2 A 1 A 0 {\displaystyle A=A_{3}A_{2}A_{1}A_{0}}
B = B 3 B 2 B 1 B 0 {\displaystyle B=B_{3}B_{2}B_{1}B_{0}}
Here each subscript represents one of the digits in the numbers.
The binary numbers A and B will be equal if all the pairs of significant digits of both numbers are equal, i.e.,
A 3 = B 3 {\displaystyle A_{3}=B_{3}} , A 2 = B 2 {\displaystyle A_{2}=B_{2}} , A 1 = B 1 {\displaystyle A_{1}=B_{1}} and A 0 = B 0 {\displaystyle A_{0}=B_{0}}
Since the numbers are binary, the digits are either 0 or 1 and the boolean function for equality of any two digits A i {\displaystyle A_{i}} and B i {\displaystyle B_{i}} can be expressed as
x i = A i B i + A ¯ i B ¯ i {\displaystyle x_{i}=A_{i}B_{i}+{\overline {A}}_{i}{\overline {B}}_{i}} we can also replace it by XNOR gate in digital electronics.
x i {\displaystyle x_{i}} is 1 only if A i {\displaystyle A_{i}} and B i {\displaystyle B_{i}} are equal.
For the equality of A and B, all x i {\displaystyle x_{i}} variables (for i=0,1,2,3) must be 1.
So the equality condition of A and B can be implemented using the AND operation as
( A = B ) = x 3 x 2 x 1 x 0 {\displaystyle (A=B)=x_{3}x_{2}x_{1}x_{0}}
The binary variable (A=B) is 1 only if all pairs of digits of the two numbers are equal.
In order to manually determine the greater of two binary numbers, we inspect the relative magnitudes of pairs of significant digits, starting from the most significant bit, gradually proceeding towards lower significant bits until an inequality is found. When an inequality is found, if the corresponding bit of A is 1 and that of B is 0 then we conclude that A>B.
This sequential comparison can be expressed logically as:
( A > B ) = A 3 B ¯ 3 + x 3 A 2 B ¯ 2 + x 3 x 2 A 1 B ¯ 1 + x 3 x 2 x 1 A 0 B ¯ 0 {\displaystyle (A>B)=A_{3}{\overline {B}}_{3}+x_{3}A_{2}{\overline {B}}_{2}+x_{3}x_{2}A_{1}{\overline {B}}_{1}+x_{3}x_{2}x_{1}A_{0}{\overline {B}}_{0}}
( A < B ) = A ¯ 3 B 3 + x 3 A ¯ 2 B 2 + x 3 x 2 A ¯ 1 B 1 + x 3 x 2 x 1 A ¯ 0 B 0 {\displaystyle (A<B)={\overline {A}}_{3}B_{3}+x_{3}{\overline {A}}_{2}B_{2}+x_{3}x_{2}{\overline {A}}_{1}B_{1}+x_{3}x_{2}x_{1}{\overline {A}}_{0}B_{0}}
(A>B) and (A < B) are output binary variables, which are equal to 1 when A>B or A<B respectively.