Title: Twos Complement numbers
1Twos Complement numbers
Lecture Notes Lab 4
A positional number system that allows the
representation of positive and negative numbers
Sign Magnitude 000 0001 1 010 2 011
3 100 -0 101 -1 110 -2 111 -3
Ones Complement 000 0001 1 010 2 011
3 100 -3 101 -2 110 -1 111 -0
Twos Complement 000 0001 1 010 2 011
3 100 -4 101 -3 110 -2 111 -1
2Creating a Two's Complement of a Negative Number
Lecture Notes Lab 4
1. Represent the magnitude of the number in
binary
3 011
2. Invert all bits (ones complement)
011 -gt 100
3. Increment the binary number by one
101 -3
3Maximum and Minimum Values
Lecture Notes Lab 4
Example 3-bits system
000 0001 1 010 2 011 3
100 -4 101 -3 110 -2 111 -1
2 bits -gt 22 positive numbers 0 to 3(22 -1)
2 bits -gt 22 negative numbers -1 to -4
MAX 2n-1 - 1 MIN -2n-1
4Twos complement operations
Lecture Notes Lab 4
Addition
001 1 010 2
101 -3 010 2
101 -3 110 -2
011 3 010 2
011 3
111 -1
1011 of
101 of
Two negative yield a positive!
Two positive yield a negative! (it does not mean
a carry overflowed)
5Twos complement operations
Lecture Notes Lab 4
Subtraction
010 2 001 1
001 1 010 2
001 1 110 -2
010 2 111 -1
-
-
011 3
111 -1
110 -2 011 3
110 -2 101 -3
010 2 101 -3
010 2 011 3
-
-
1011 of
101 of
Subtract a positive from a negative yields
positive!
Subtract a negative from a positive yields a
negative!
6Design of an Adder/Substractor
Lecture Notes Lab 4
By using structural behavior, the system consists
on the specification of the connection among the
different subsystems
See example in black_box.vhd