ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Digital Logic Design
    CC-110
    Progress0 / 63 topics
    Topics
    1. Introduction to Digital Systems2. Number Systems3. Introduction to Boolean Algebra4. Basic theorems and properties of Boolean Algebra5. Boolean Functions6. Logic Gates7. NAND and NOR Implementation8. Representation of Function in Sum of Minterms or Product of Maxterms9. Simplification of Boolean function using Karnaugh Map10. Don't care Conditions11. The Tabulation Method12. Introduction to Combinational Logic13. Design of Adders14. Design of Subtractors15. Code Convertors16. Analysis Procedure of Combinational Circuits17. Binary Parallel Adders18. Decimal Adders19. Magnitude Comparator20. Decoders and its applications21. Multiplexers22. Demultiplexers23. Encoders24. ROM25. Programmable Logic Array (PLA)26. Introduction to Sequential Circuits27. Basic Flip Flop28. Clocked RS Flip Flop29. Clocked D Flip Flop30. Clocked JK Flip Flop31. Clocked T Flip Flop32. Analysis of Clocked Sequential Circuits33. State Reduction and Assignment34. Flip Flop Excitation tables35. Design Procedure36. Design of Counters37. Design with State Equations38. Introduction to Registers39. Shift Registers40. Ripple Counters41. Synchronous Counters42. Timing Sequences43. Memory Unit44. Random Access Memory45. Introduction to Programmable Logic Devices (CPLD, FPGA)46. Lab Assignments using tools such as Verilog HDL/VHDL, MultiSim47. Familiarization with Digital Electronic Trainer48. Logic gates operations49. Half Adder Operation50. Full Adder Operation51. Half Subtractor Operation52. Full Subtractor Operation53. 7-Segment Display Operation54. Decoder Operation55. BCD To 7-Segment Display56. Multiplexer Operation57. Using Multiplexer and Demultiplexer/Decoder58. Multiplexing 7-Segment Displays59. Comparator Operations60. D Latch and Flip-Flop Operation61. Latching BCD Data for Displaying On 7-Segment Display62. JK Flip-Flop Operation63. Random Access Memories
    CC-110›Magnitude Comparator
    Digital Logic DesignTopic 19 of 63

    Magnitude Comparator

    11 minread
    1,847words
    Intermediatelevel

    Magnitude Comparator

    A magnitude comparator is a digital circuit used to compare two binary numbers (or signals) and determine their relative magnitudes. It outputs signals that indicate whether one number is greater than, less than, or equal to the other. Magnitude comparators are fundamental in many digital applications, including processors, arithmetic logic units (ALUs), and decision-making systems.

    A magnitude comparator can compare numbers of any size, but it is most commonly used to compare n-bit binary numbers.

    Functionality of a Magnitude Comparator

    For two binary numbers AAA and BBB, the magnitude comparator compares them and produces three outputs:

    • Greater than (A > B)
    • Equal to (A = B)
    • Less than (A < B)

    The outputs are typically represented by:

    • A>BA > BA>B (1 if AAA is greater than BBB, 0 otherwise)
    • A=BA = BA=B (1 if AAA is equal to BBB, 0 otherwise)
    • A<BA < BA<B (1 if AAA is less than BBB, 0 otherwise)

    Truth Table for a 1-bit Magnitude Comparator

    To understand the working of a magnitude comparator, let's first look at a simple 1-bit magnitude comparator.

    A B A > B A = B A < B
    0 0 0 1 0
    0 1 0 0 1
    1 0 1 0 0
    1 1 0 1 0
    • When A=B=0A = B = 0A=B=0, the output shows A=BA = BA=B is true.
    • When A=1A = 1A=1 and B=0B = 0B=0, the output shows A>BA > BA>B is true.
    • When A=0A = 0A=0 and B=1B = 1B=1, the output shows A<BA < BA<B is true.
    • When A=B=1A = B = 1A=B=1, the output shows A=BA = BA=B is true.

    Generalized Magnitude Comparator for n-bit Numbers

    For n-bit numbers A=(AnAn−1...A1A0)A = (A_n A_{n-1} ... A_1 A_0)A=(An​An−1​...A1​A0​) and B=(BnBn−1...B1B0)B = (B_n B_{n-1} ... B_1 B_0)B=(Bn​Bn−1​...B1​B0​), the magnitude comparator must compare each corresponding bit and generate three outputs:

    • A > B
    • A = B
    • A < B

    The comparator works by evaluating each bit from the most significant bit (MSB) to the least significant bit (LSB), performing a stepwise comparison.

    Steps for Comparison:

    1. Start with the most significant bit (MSB): Compare AnA_nAn​ with BnB_nBn​. The result of this comparison will determine if AAA is greater than, less than, or equal to BBB at this stage.
    2. If An=BnA_n = B_nAn​=Bn​, move to the next significant bit, An−1A_{n-1}An−1​ and Bn−1B_{n-1}Bn−1​, and repeat the comparison.
    3. If at any bit, Ai>BiA_i > B_iAi​>Bi​, then A>BA > BA>B, and the comparison stops there.
    4. If at any bit, Ai<BiA_i < B_iAi​<Bi​, then A<BA < BA<B, and the comparison stops there.
    5. If all bits are equal, then A=BA = BA=B.

    Example: 3-bit Magnitude Comparator

    Consider two 3-bit numbers:

    • A=101A = 101A=101 (5 in decimal)
    • B=011B = 011B=011 (3 in decimal)

    The comparison steps would be:

    1. Compare A2A_2A2​ (MSB) and B2B_2B2​: A2=1A_2 = 1A2​=1 and B2=0B_2 = 0B2​=0. Since 1>01 > 01>0, we immediately know A>BA > BA>B, and there’s no need to compare the other bits.

    Design of a Magnitude Comparator

    The design of a magnitude comparator depends on how many bits need to be compared. A simple magnitude comparator can be implemented using:

    • XOR gates: To detect equality of individual bits.
    • AND/OR gates: To propagate the "greater than" or "less than" information.
    • Inverters: To handle the logic of the greater-than and less-than conditions.

    Basic Building Blocks of a Magnitude Comparator:

    1. Equality Check (A = B): For each bit, use an XOR gate. If Ai=BiA_i = B_iAi​=Bi​, then the XOR gate will output 0; if they are different, the XOR gate will output 1. A 1 means the bits are not equal.

      • Equality Logic: The output for all bits A=BA = BA=B will be 1 if all individual bit pairs are equal.
    2. Greater than (A > B): To determine if AAA is greater than BBB, evaluate each bit starting from the MSB. The condition Ai>BiA_i > B_iAi​>Bi​ is satisfied if Ai=1A_i = 1Ai​=1 and Bi=0B_i = 0Bi​=0 at the first such position from the left.

      • Greater-than Logic: If Ai>BiA_i > B_iAi​>Bi​ is true for any bit, the comparator outputs 1 for the greater-than output.
    3. Less than (A < B): This is the inverse of the greater-than logic. If Ai=0A_i = 0Ai​=0 and Bi=1B_i = 1Bi​=1 for any bit, then AAA is less than BBB.

    For an n-bit Comparator:

    • Equality: For each pair of bits AiA_iAi​ and BiB_iBi​, use an XOR gate. All XOR outputs are combined using an AND gate to generate A=BA = BA=B.
    • Greater than: Use the logic of propagation: if Ai>BiA_i > B_iAi​>Bi​ is detected at any bit, the greater-than signal is set to 1.
    • Less than: This is the opposite of the greater-than condition.

    Example: 4-bit Magnitude Comparator Logic

    Consider the comparison of two 4-bit numbers A=A3A2A1A0A = A_3 A_2 A_1 A_0A=A3​A2​A1​A0​ and B=B3B2B1B0B = B_3 B_2 B_1 B_0B=B3​B2​B1​B0​.

    Equality Output (A = B):

    The equality output is true if all corresponding bits of AAA and BBB are the same. This can be computed as:

    A = B=(A3⊕B3)⋅(A2⊕B2)⋅(A1⊕B1)⋅(A0⊕B0)\text{A = B} = (A_3 \oplus B_3) \cdot (A_2 \oplus B_2) \cdot (A_1 \oplus B_1) \cdot (A_0 \oplus B_0)A = B=(A3​⊕B3​)⋅(A2​⊕B2​)⋅(A1​⊕B1​)⋅(A0​⊕B0​)

    Greater than Output (A > B):

    To determine if AAA is greater than BBB, you need to check each bit, starting from the MSB. If Ai>BiA_i > B_iAi​>Bi​ for some iii, then A>BA > BA>B.

    A > B=(A3⋅¬B3)+((A3=B3)⋅A2⋅¬B2)+…\text{A > B} = (A_3 \cdot \neg B_3) + ((A_3 = B_3) \cdot A_2 \cdot \neg B_2) + \ldotsA > B=(A3​⋅¬B3​)+((A3​=B3​)⋅A2​⋅¬B2​)+…

    Less than Output (A < B):

    To check if AAA is less than BBB, check for the condition where Ai<BiA_i < B_iAi​<Bi​ for the leftmost bit that differs.

    A < B=(B3⋅¬A3)+((A3=B3)⋅B2⋅¬A2)+…\text{A < B} = (B_3 \cdot \neg A_3) + ((A_3 = B_3) \cdot B_2 \cdot \neg A_2) + \ldotsA < B=(B3​⋅¬A3​)+((A3​=B3​)⋅B2​⋅¬A2​)+…

    Applications of Magnitude Comparators

    Magnitude comparators are used in many digital systems, including:

    • ALUs: For comparing operands in arithmetic operations.
    • Sorting networks: To compare elements and order them.
    • Control systems: For conditional branching or decision-making based on magnitude.
    • Data transmission systems: For determining if one data signal is larger than another.

    Conclusion

    A magnitude comparator is a vital component in digital logic design that helps compare two binary numbers and determine if one is greater than, less than, or equal to the other. It is used in various applications, including arithmetic operations, control systems, and sorting. The design can be expanded to compare n-bit numbers by using logic gates such as XOR, AND, and OR, which are combined to generate the desired outputs.

    Previous topic 18
    Decimal Adders
    Next topic 20
    Decoders and its applications

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time11 min
      Word count1,847
      Code examples0
      DifficultyIntermediate