From Surf Wiki (app.surf) — the open knowledge base
Digital comparator
Digital electronic component which compares two binary numbers
Digital electronic component which compares two binary numbers
A digital comparator or magnitude comparator is a hardware electronic device that takes two numbers as input in binary form and determines whether one number is greater than, less than or equal to the other number. Comparators are used in central processing units (CPUs) and microcontrollers (MCUs). Examples of digital comparator include the CMOS 4063 and 4585 and the TTL 7485 and 74682.
An XNOR gate is a basic comparator, because its output is "1" only if its two input bits are equal.
The analog equivalent of digital comparator is the voltage comparator. Many microcontrollers have analog comparators on some of their inputs that can be read or trigger an interrupt.
Implementation

Consider two 4-bit binary numbers A and B so
.png)
A=A_3A_2A_1A_0
B=B_3B_2B_1B_0
Here each subscript represents one of the digits in the numbers.
;Equality 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, A_2=B_2, A_1=B_1 and 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 and B_i can be expressed as
x_i= A_i \cdot B_i + \overline{A_i} \cdot \overline{B_i} we can also replace it by XNOR gate in digital electronics.
x_i is 1 only if A_i and B_i are equal.
For the equality of A and B, all 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 \cdot x_2 \cdot x_1 \cdot x_0
The binary variable (A=B) is 1 only if all pairs of digits of the two numbers are equal.
;Inequality
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 AB.
This sequential comparison can be expressed logically as:
(AB)=A_3 \cdot \overline{B_3} + x_3 \cdot A_2 \cdot \overline{B_2} + x_3 \cdot x_2 \cdot A_1 \cdot \overline{B_1} + x_3 \cdot x_2 \cdot x_1 \cdot A_0 \cdot \overline{B_0}
(A
(A B) and (A B or A

]]
References
- {{cite book
This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.
Ask Mako anything about Digital comparator — get instant answers, deeper analysis, and related topics.
Research with MakoFree with your Surf account
Create a free account to save articles, ask Mako questions, and organize your research.
Sign up freeThis content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.
Report