# Compare two numbers of four bits

I have two numbers both with four bits (a3 to a0 and b3 to b0 reading from left to right) and I would like to find out if a is bigger than b. I have drawn a solution of mine and a short mathematical explanation of it, it would be amazing if somebody can tell me if this is correct. So my idea is to to use full adders (which are named VA), where I have a, b and the carry from before as inputs. The carry from the current adder and q_{i} are outputs of it. I negate all of my bits of b,setting C0 to one to add one so I have a two's complement and than I add both numbers. One of my sources say's, that a>b when sign=0 and z=0. Z is 1 when all q_{i} are zero. And sign means (concerning my sources), that q3 is zero. So in the end I came up combining it like the way I did on the photo.

Am I right with this? Why is there no use of c3? • Negating all of your bits is not two complement. – DonFusili Sep 5 '18 at 8:02
• @DonFusil note C0 = 1. He is achieving twos complement by inverting and adding one although this is not explained. – RoyC Sep 5 '18 at 9:07
• @RoyC Ah, that'll teach me to assume the text and diagram explain and show the same, my bad. – DonFusili Sep 5 '18 at 9:16
• @RoyC Thanks for saying this, sorry I forgot to talk about this. Is that the correct twos complement then? – DORpapst Sep 5 '18 at 9:23
• Yes that is good. – RoyC Sep 5 '18 at 9:24

The fundamental error with this and why you are not using c3 is that you need to represent the twos complement input and output with the range 15 to -15 as a five bit quantity. This means that c3 is q4 of the output and the sign bit.

• So do you mean the function would be correct, if I would put q3 to OR as well and move the current q3 to the carry with c3? – DORpapst Sep 5 '18 at 9:24
• That is correct. – RoyC Sep 5 '18 at 9:26

Search for 4-bit comparator 3-bit comparator 4-bit comparator : • @RoyC I agree with you, I am so sorry. I will add the links where I got those circuits. Take it as an example, unfortunatelly the bad one. – Marko Buršič Sep 5 '18 at 15:43
• @RoyC I did change the exaple with better one. – Marko Buršič Sep 5 '18 at 15:47