EveryCircuit
Contact
Reviews
Home
jason9
modified 5 years ago

4 Bit Recursive Comparator

7
0
272
01:58:47
The top four logic sources are the first number and the bottom four are the second number. The most significant bit is on top. Orange means the top number is less than the bottom number. Light blue (or cyan if you prefer) means the top number is greater than the bottom number. Green means they’re equal. The first step this does is a bitwise comparison. A comparison is then done between the most significant bit of each number, or if they’re equal the next bit pair down, or if they’re equal, the next bit pair down, and so on, and if all bit pairs are equal then the result is that the numbers are equal. But in a naïve implementation this has the same problem as the ripple carry adder. If all bit pairs are equal except the least significant bit of each number then the comparison will have to ripple up through every bit pair comparison stage above it, which is slow. I get around that here by using a recursive strategy so that the worst case time is reduced from O(n) to O(log n) where n is the number of bits (you may look up “big O notation” if you don’t understand what O(n) and O(log n) mean). Furthermore, by using this recursive strategy the comparison time is equal regardless of which bit pairs are and aren’t different. On the other hand, the ripple comparator compares very fast when the most significant bit of each number is different and very slow when all bit pairs except the least significant bit of each number is different. For very low numbers of bits such as 4 as I’ve shown here, there’s very little benefit. With ripple comparison the worst case is 3 stages of propagation and for recursive it’s always exactly 2 stages. For more bits there can be much greater advantages. For 64 bits the ripple comparator’s worst case is 63 stages, but with the recursive comparator it’s always exactly 6 stages.
published 5 years ago

EveryCircuit is an easy to use, highly interactive circuit simulator and schematic capture tool. Real-time circuit simulation, interactivity, and dynamic visualization make it a must have application for professionals and academia. EveryCircuit user community has collaboratively created the largest searchable library of circuit designs. EveryCircuit app runs online in popular browsers and on mobile phones and tablets, enabling you to capture design ideas and learn electronics on the go.

Copyright © 2026 by MuseMaze, Inc.     Terms of use     Privacy policy