我有一个带符号的二进制数字“ a”,并且我想使用减法器来确定此数字是否大于或等于或小于另一个数字“ b”。 this is a related topic
在上面的线程中,答案使用进位位。
在我看来,我们只能使用MSB,因为在2的补码计算中,MSB告诉签出输出。如果输出符号为1,我们知道我们必须有一个小于,而符号为0,那么我们知道我们有一个大于或等于。但是然后我有溢出的问题。
例如,如果我有两个5位数字
5: 00101
-5: 11011
dec = 6+(-5) = 1
00110
+11011
=====
100001
carry = 1,MSB = 0,so MSB =0 or carry = 1 is greater than or equal to.
dec = 5-6=-1
00101
+11010
=====
011111
carry = 0,MSB = 1,so MSB =1 or carry = 0 is less than.
dec 6 - (-10) = 16
00110
+01010
=====
010000
carry = 0,MSB =1,this would be wrong if i evaluate to 6 less than -10.
所以我有四个问题:
1. should I use carry out or MSB as the condition? 2. what to do for the overflow condition? 3. how could i design a general comparator using the subtractor method? 4. I know I could make a explicit if else statement on the sign bit of the input and output and determine if one is bigger or less than the other. But is there a way of not doing those if and else,but just use the MSB or carry flag for the judgement?
非常感谢您的帮助!