• Support PF! Buy your school textbooks, materials and every day products Here!

Comparator of 2 bit numbers

  • Thread starter cdummie
  • Start date
  • #1
147
5
< Mentor Note -- thread moved to HH from the technical engineering forums, so no HH Template is shown >

Is there a way to create two bit numbers comparator using one 2 to 4 decoder and standard logic gates?
 
Last edited by a moderator:

Answers and Replies

  • #2
34,039
9,883
I would avoid the decoder because it is easier without, but it is possible in both cases (and the decoder just has standard logic gates anyway).
 
  • #3
analogdesign
Science Advisor
1,139
354
used a K-map to figure out how to do it with logic gates. The decoder will only be useful in the sense it can be used to implement certain logic equations.
 
  • #4
berkeman
Mentor
56,814
6,782
Is there a way to create two bit numbers comparator using one 2 to 4 decoder and standard logic gates?
Do you mean a logic block that takes in two 2-bit numbers, and has one output that is either high or low depending on the relative magnitude of the two 2-bit numbers? What if they are equal? Can you show us a truth table for the function that you want to implement?

And is this for a synchronous (clocked) application, or does it need to run asynchronously?
 
  • #5
Baluncore
Science Advisor
2019 Award
7,410
2,452
Is there a way to create two bit numbers comparator using one 2 to 4 decoder and standard logic gates?
Yes there is. But it is easier to do it with a 1 of 16 data selector and no gates than with a data decoder.

But two XOR gates driving one NOR gate would achieve the same.
 
  • #6
147
5
Do you mean a logic block that takes in two 2-bit numbers, and has one output that is either high or low depending on the relative magnitude of the two 2-bit numbers? What if they are equal? Can you show us a truth table for the function that you want to implement?

And is this for a synchronous (clocked) application, or does it need to run asynchronously?
Screenshot_2.png


This is the truth table. X is active if the A1A0 is greater that B1B0 if they have the same value Y is active and if B1B0 is greater than A1A0 then Z is active. Problem is, that i have to use 2 to 4 decoder and i don't know how to make only two inputs since i have 4(A1, A0, B1 and B0) and make it work this way.
 
  • #7
34,039
9,883
Connect the decoder to something and ignore its output, if the decoder has to appear in the system?
Well, you can connect it to some part of the input, and use its internal gates (C1 AND C0, C1 AND NOT C0, ...) as intermediate results.

It is possible to produce all outputs with 12 logic gates, not including NOT, without the decoder. Fewer if you count XOR as one, or use gates with more than 2 inputs.
 
  • #8
147
5
Connect the decoder to something and ignore its output, if the decoder has to appear in the system?
Well, you can connect it to some part of the input, and use its internal gates (C1 AND C0, C1 AND NOT C0, ...) as intermediate results.

It is possible to produce all outputs with 12 logic gates, not including NOT, without the decoder. Fewer if you count XOR as one, or use gates with more than 2 inputs.
Decoder has to appear in system, and it has to be 2 to 4 decoder and standard logical gates are allowed but still i don't understand how can i do it with just one decoder and logic gates.
 
  • #9
berkeman
Mentor
56,814
6,782
Well, just use the single decoder with the first 2 inputs, and then write a truth table using the 4 outputs of that decoder and the other 2 inputs. Kind of a dorky way to have to do it, but it can work.

Alternately, use the decoder to generate the outputs, and use logic gates on the 4 inputs to generate the 2-bit input to the decoder.

Try writing the new truth tables for each of those options, to see which uses fewer gates (probably the second option will be better, but that's just a guess).
 
  • #10
34,039
9,883
Decoder has to appear in system, and it has to be 2 to 4 decoder and standard logical gates are allowed but still i don't understand how can i do it with just one decoder and logic gates.
You can reproduce every truth table with logic gates. This can be done in more or less efficient ways, but it is always possible and there is a direct and natural way to find a solution. And as mentioned, the decoder can be used somewhere in the process.
 
  • #11
147
5
Well, just use the single decoder with the first 2 inputs, and then write a truth table using the 4 outputs of that decoder and the other 2 inputs. Kind of a dorky way to have to do it, but it can work.

Alternately, use the decoder to generate the outputs, and use logic gates on the 4 inputs to generate the 2-bit input to the decoder.

Try writing the new truth tables for each of those options, to see which uses fewer gates (probably the second option will be better, but that's just a guess).
Thanks, i will try to do it that way.
 

Related Threads on Comparator of 2 bit numbers

Replies
2
Views
6K
  • Last Post
Replies
3
Views
740
Replies
7
Views
4K
  • Last Post
Replies
1
Views
4K
  • Last Post
Replies
7
Views
5K
Replies
3
Views
1K
Replies
4
Views
3K
Replies
2
Views
479
Replies
5
Views
1K
Top