Digital comparator
Encyclopedia
A digital comparator or magnitude comparator is a hardware
Computer hardware
Personal computer hardware are component devices which are typically installed into or peripheral to a computer case to create a personal computer upon which system software is installed including a firmware interface such as a BIOS and an operating system which supports application software that...

 electronic device that takes two numbers as input in binary
Binary numeral system
The binary numeral system, or base-2 number system, represents numeric values using two symbols, 0 and 1. More specifically, the usual base-2 system is a positional notation with a radix of 2...

 form and determines whether one number is greater than, less than or equal to the other number. Comparators are used in a central processing unit
Central processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...

s (CPU) and microcontroller
Microcontroller
A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM...

s. Examples of digital comparator include the CMOS 4063 and 4585 and the TTL 7485 and 74682-'89.

The analog
Analog signal
An analog or analogue signal is any continuous signal for which the time varying feature of the signal is a representation of some other time varying quantity, i.e., analogous to another time varying signal. It differs from a digital signal in terms of small fluctuations in the signal which are...

 equivalent of digital comparator is the voltage comparator
Comparator
In electronics, a comparator is a device that compares two voltages or currents and switches its output to indicate which is larger. They are commonly used in devices such as Analog-to-digital converters .- Input voltage range :...

. Many microcontroller
Microcontroller
A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM...

s have analog comparators on some of their inputs that can be read or trigger an interrupt
Interrupt
In computing, an interrupt is an asynchronous signal indicating the need for attention or a synchronous event in software indicating the need for a change in execution....

.

Comparator truth tables

The operation of a single bit digital comparator can be expressed as a truth table
Truth table
A truth table is a mathematical table used in logic—specifically in connection with Boolean algebra, boolean functions, and propositional calculus—to compute the functional values of logical expressions on each of their functional arguments, that is, on each combination of values taken by their...

:
Inputs | Outputs
0 0 0 1 0
0 1 0 0 1
1 0 1 0 0
1 1 0 1 0

The operation of a two bit digital comparator can be expressed as a truth table:
Inputs | Outputs
0 0 0 0 0 1 0
0 0 0 1 1 0 0
0 0 1 0 1 0 0
0 0 1 1 1 0 0
0 1 0 0 0 0 1
0 1 0 1 0 1 0
0 1 1 0 1 0 0
0 1 1 1 1 0 0
1 0 0 0 0 0 1
1 0 0 1 0 0 1
1 0 1 0 0 1 0
1 0 1 1 1 0 0
1 1 0 0 0 0 1
1 1 0 1 0 0 1
1 1 1 0 0 0 1
1 1 1 1 0 1 0

Implementation

Consider two 4-bit binary numbers A and B such that





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.,

, , and

Since the numbers are binary, the digits are either 0 or 1 and the boolean function for equality of any two digits and can be expressed as

.
is 1 only if and are equal.

For the equality of A and B, all variables (for i=0,1,2,3) must be 1.

So the quality condition of A and B can be implemented using the AND
AND gate
The AND gate is a basic digital logic gate that implements logical conjunction - it behaves according to the truth table to the right. A HIGH output results only if both the inputs to the AND gate are HIGH . If neither or only one input to the AND gate is HIGH, a LOW output results...

 operation as



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
Most significant bit
In computing, the most significant bit is the bit position in a binary number having the greatest value...

, 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) and (A < B) are output binary variables, which are equal to 1 when A>B or A


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK