053-2's-complement-comparator - Steve Lumetta
9/25/2016
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering
ECE 120: Introduction to Computing
A Comparator for 2's Complement
ECE 120: Introduction to Computing
? 2016 Steven S. Lumetta. All rights reserved.
slide 1
Comparing 2's Complement Is Different from Unsigned
Let's design a comparator for 2's complement numbers. Is the function the same as with unsigned (like addition)? For unsigned, 1001 > 0101.
Is the same true with 2's complement? No.
Should we just start over?
ECE 120: Introduction to Computing
? 2016 Steven S. Lumetta. All rights reserved.
slide 2
Start with the Sign Bits
Let's try a little harder first... If we compare two non-negative numbers, the approach IS the same. Right? Maybe we can just use some extra logic to handle the sign bits?
ECE 120: Introduction to Computing
? 2016 Steven S. Lumetta. All rights reserved.
Consider All Possible Combinations of Sign Bits
Let's make a table based on the sign bits:
As Bs interpretation
0 0 A 0 AND B 0
0 1 A 0 AND B < 0 1 0 A < 0 AND B 0 1 1 A < 0 AND B < 0
solution use unsigned comparator
A > B
A < B
unknown
slide 3
ECE 120: Introduction to Computing
? 2016 Steven S. Lumetta. All rights reserved.
slide 4
9/25/2016
Interpret 2's Complement as Unsigned
Remember our "simple" rule for translating 2's complement bit patterns to decimal? The pattern A = aN-1aN-2 ... a1a0 has value VA = -aN-12N-1 + aN-22N-2 + ... + a020 Let A be negative (aN-1 = 1). Interpreted as unsigned, the same bits have value VA + 2N.*
*The statement is true by definition of 2's complement, actually.
ECE 120: Introduction to Computing
? 2016 Steven S. Lumetta. All rights reserved.
slide 5
Negative Numbers Can be Compared Directly
What happens if we feed two negative 2's complement numbers into our unsigned comparator? We compare VA + 2N with VB + 2N. And we get an answer: . Let's say that we find VA + 2N < VB + 2N. In that case, VA < VB, so we have the right answer for 2's complement. The same result holds for other answers.
ECE 120: Introduction to Computing
? 2016 Steven S. Lumetta. All rights reserved.
slide 6
We Need Special Logic for the Sign Bits
Now we can complete our table:
As Bs interpretation
0 0 A 0 AND B 0
0 1 A 0 AND B < 0
solution use unsigned comparator
A > B
1 0 A < 0 AND B 0
A < B
1 1 A < 0 AND B < 0 use unsigned
comparator
ECE 120: Introduction to Computing
? 2016 Steven S. Lumetta. All rights reserved.
slide 7
Simply Flip the Wires on the Most Significant Bit
Can we just flip the wires on the sign bits? For As = 0 and Bs = 1, we feed in AN-1 = 1 and BN-1 = 0, and the unsigned comparator produces A > B. For As = 1 and Bs = 0, we feed in AN-1 = 0 and BN-1 = 1, and the unsigned comparator produces A < B.
What about when As = Bs? Flipping the bits then has no effect!
Answers are also correct in those cases.
ECE 120: Introduction to Computing
? 2016 Steven S. Lumetta. All rights reserved.
slide 8
One Comparator with a Control Signal can Do Both
Can we use a single comparator to perform both kinds of comparisons? Yes, if we add a control signal S to tell the comparator whether to do unsigned
(S=0) or 2's complement (S=1) comparison.
Simply XOR'ing the most significant bits of A and B with S suffices. This approach leverages flexibility in the
problem to reduce the logic needed. Analyze the design to understand how it works.
ECE 120: Introduction to Computing
? 2016 Steven S. Lumetta. All rights reserved.
slide 9
9/25/2016
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- lecture 19 bit operations
- bit operations ohio state university
- coding schemes used with data converters rev a
- mips arithmetic howard huang
- 2 s complement and floating point
- 9 binary numbers codes stanford university
- l08 arithmetic multipliers
- two s complement arithmetic edward bosworth
- binary arithmetic bit shifting 2s complement intro to
- fixed point arithmetic an introduction
Related searches
- 1 s complement and 2 s complement converter
- 2 s complement negative number
- 2 s complement form
- adding 3 values 2 s complement numbers calculator
- n bit 2 s complement largest value
- 2 s complement subtraction calculator
- hexadecimal to 2 s complement calculator
- 8 bit 2 s complement calculator
- adding 2 s complement numbers
- what is 2 s complement form
- 2 s complement addition calculator
- 2 s complement addition