Upload
gcmath1003
View
362
Download
2
Tags:
Embed Size (px)
Citation preview
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
1.15Integers and2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Goal
To be able to specify how integers are stored by the computer in 2’s complement format.
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Integers
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Integers
Integers and Real Numbers are stored in different ways inside the computer.
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Integers
Integers and Real Numbers are stored in different ways inside the computer.
35 and 35.0 to human beings represent the same value.
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Integers
Integers and Real Numbers are stored in different ways inside the computer.
35 and 35.0 to human beings represent the same value.
35 35.0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Integers
Integers and Real Numbers are stored in different ways inside the computer.
35 and 35.0 to human beings represent the same value.
However, the computer “handles” these numbers with different mechanisms.
35 35.0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
35
Integers
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Today’s computers store integers usually in 32 bits.
35
Integers
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Today’s computers store integers usually in 32 bits.
For the purpose of our discussions, we will imagine that we are working with an older computer that stores
integers in 8 bits. Concepts that we will discuss are valid whether the integers are in 32 bits or 8 bits.
35
Integers
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
35
Integers
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
3510, as an 8 bit binary number, is 001000112
35
Integers
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
3510, as an 8 bit binary number, is 001000112
That’s how the computer will store 3510
35
Integers
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
3510, as an 8 bit binary number, is 001000112
That’s how the computer will store 3510
But we know that integers include both positive and negative whole numbers.
35
Integers
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Sign and Magnitude
001000112signbit
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Sign and Magnitude
How does the computer store negative numbers? (Remember: bits are only 0 or 1)
001000112signbit
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Sign and Magnitude
How does the computer store negative numbers? (Remember: bits are only 0 or 1)
One option would be to use the leftmost bit as a sign bit (0 for positive numbers and 1 for negative numbers).
001000112signbit
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Sign and Magnitude
How does the computer store negative numbers? (Remember: bits are only 0 or 1)
One option would be to use the leftmost bit as a sign bit (0 for positive numbers and 1 for negative numbers).
001000112signbit
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
How does the computer store negative numbers? (Remember: bits are only 0 or 1)
One option would be to use the leftmost bit as a sign bit (0 for positive numbers and 1 for negative numbers).
001000112signbit
Sign and Magnitude
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
We’ll use the other 7 bits for the value (or magnitude) of the number.
001000112signbit
Sign and Magnitude
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
We’ll use the other 7 bits for the value (or magnitude) of the number.
001000112magnitude
Sign and Magnitude
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
We’ll use the other 7 bits for the value (or magnitude) of the number.
001000112magnitude
Sign and Magnitude
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Using this scheme, we can represent -3510 as 101000112
3510 as a 7 bit number is 01000112
The sign bit will be a 1 to represent the minus sign
101000112signbit magnitude
Sign and Magnitude
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
In this scheme, what is 000000002 and 100000002?
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
In this scheme, what is 000000002 and 100000002?
000000002 is positive 0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
In this scheme, what is 000000002 and 100000002?
000000002 is positive 0
+0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
In this scheme, what is 000000002 and 100000002?
000000002 is positive 0
100000002 is negative 0
+0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
In this scheme, what is 000000002 and 100000002?
000000002 is positive 0
100000002 is negative 0
+0 -0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
In this scheme, what is 000000002 and 100000002?
000000002 is positive 0
100000002 is negative 0
Believe or not, having two ways to represent 0 causes big problems.
+0 -0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
+0 -0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
Depending on the arithmetic operation, we can get a result of 000000002 or 100000002.
+0 -0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
Depending on the arithmetic operation, we can get a result of 000000002 or 100000002.
If we had this situation, there would have to be special circuitry to test for positive 0 and negative 0 - this adds
complexity to the computer.
+0 -0
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
Another problem that arises has to do with the addition of a positive and a negative number.
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Problems
Another problem that arises has to do with the addition of a positive and a negative number.
The computer would have to deal with the sign bit (which does not represent value).
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement
So a scheme was invented to address these issues.
It is called 2’s complement.
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
In 2’s complement, positive numbers are represented in their normal binary equivalent.
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Negative number representation is found in the following manner:
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Negative number representation is found in the following manner:
1. calculate the magnitude of the number
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Negative number representation is found in the following manner:
1. calculate the magnitude of the number
2. subtract the number from 111111112
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Negative number representation is found in the following manner:
1. calculate the magnitude of the number
2. subtract the number from 111111112
3. add 1 to the result
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement
1. calculate the magnitude of the number
2. subtract the number from 111111112
3. add 1 to the result
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement
1. calculate the magnitude of the number
2. subtract the number from 111111112
3. add 1 to the result
Calculate the 2’s complementform of -10410
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement
1. calculate the magnitude of the number
2. subtract the number from 111111112
3. add 1 to the result
Calculate the 2’s complementform of -10410
1. 10410 = 011010002
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement
1. calculate the magnitude of the number
2. subtract the number from 111111112
3. add 1 to the result
Calculate the 2’s complementform of -10410
1. 10410 = 011010002
2. 111111112 - 011010002 = 100101112
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement
1. calculate the magnitude of the number
2. subtract the number from 111111112
3. add 1 to the result
Calculate the 2’s complementform of -10410
1. 10410 = 011010002
2. 111111112 - 011010002 = 100101112
3. 100101112 + 12 = 100110002
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement
1. calculate the magnitude of the number
2. subtract the number from 111111112
3. add 1 to the result
Calculate the 2’s complementform of -10410
1. 10410 = 011010002
2. 111111112 - 011010002 = 100101112
3. 100101112 + 12 = 100110002
Therefore, -10410 = 100110002
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Now, let us explore a less complicated way of calculating the 2’s complement form of a negative number:
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Now, let us explore a less complicated way of calculating the 2’s complement form of a negative number:
1. calculate the magnitude of the number
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Now, let us explore a less complicated way of calculating the 2’s complement form of a negative number:
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Now, let us explore a less complicated way of calculating the 2’s complement form of a negative number:
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
Calculate the 2’s complementform of -10410
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
Calculate the 2’s complementform of -10410
10410 = 011010002
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 011010002
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 011010002
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 011010002
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 011010002
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 011010002
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 011010002
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 0110100021
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 01101000210
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 011010002100
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
10410 = 0110100021001
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -10410
-10410 = 100110002
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 000000012
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 000000012
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 000000012
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 0000000121
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 00000001211
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 000000012111
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 0000000121111
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 00000001211111
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 000000012111111
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
110 = 0000000121111111
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -110
-110 = 111111112
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
4210 = 001010102
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
110 = 001010102
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
110 = 0010101021
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
110 = 00101010210
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
110 = 001010102101
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
110 = 0010101021010
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
110 = 00101010210101
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
110 = 001010102101011
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the 2’s complementform of -4210
-4210 = 110101102
2’s Complement2’s complement (a better way)
1. calculate the magnitude of the number
2. starting from the rightmost bit, look for the first bit that is a 1
3. “invert” all bits to the left of the 1
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
111101112
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
111101112
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
1111011120
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
11110111200
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
111101112001
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
1111011120010
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
11110111200100
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
111101112001000
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
1111011120010000
2’s Complement
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
1111011120010000
2’s Complement this method is for negative numbers
only
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s complement(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
Calculate the decimal value of111101112
1111011120010000 = -910
2’s Complement this method is for negative numbers
only
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the decimal value of111010002
2’s Complement2’s complement
(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the decimal value of111010002
111010002
2’s Complement2’s complement
(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the decimal value of111010002
111010002
2’s Complement2’s complement
(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the decimal value of111010002
1110100021
2’s Complement2’s complement
(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the decimal value of111010002
11101000210
2’s Complement2’s complement
(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the decimal value of111010002
111010002100
2’s Complement2’s complement
(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the decimal value of111010002
1110100021000
2’s Complement2’s complement
(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate the decimal value of111010002
1110100021000 = -2410
2’s Complement2’s complement
(calculating the decimal equivalent)
1. starting from the rightmost bit, look for the first bit that is a 1
2. “invert” all bits to the left of the 1
3. calculate the magnitude of the number
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
01011001
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
01011001
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
01011001
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
010110012
7210
+1710
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
2’s Complement and Addition
Calculate 7210 + 1710
Since these are both positive, this is straightforward
010010002
+000100012
010110012
7210
+1710
sign
bit
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 10410 + (-4210)
Here we add a negative number to a positive number
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 10410 + (-4210)
Here we add a negative number to a positive number
10410 + -4210
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 10410 + (-4210)
Here we add a negative number to a positive number
011010002
+110101102
10410 + -4210
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 10410 + (-4210)
Here we add a negative number to a positive number
011010002
+110101102
10410 + -4210
2’s Complement and Addition
-4210 in 2’s complement?
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 10410 + (-4210)
Here we add a negative number to a positive number
011010002
+110101102
10410 + -4210
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 10410 + (-4210)
Here we add a negative number to a positive number
011010002
+110101102
1001111102
10410 + -4210
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 10410 + (-4210)
Here we add a negative number to a positive number
011010002
+110101102
1001111102
10410 + -4210
since we are only using 8 bit numbers,
the ninth bit is simply dropped
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 10410 + (-4210)
Here we add a negative number to a positive number
011010002
+110101102
1001111102
10410 + -4210
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 10410 + (-4210)
Here we add a negative number to a positive number
011010002
+110101102
1001111102
10410 + -4210
sign
bit
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 2710 + (-3510)
Here we add a negative number to a positive number
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 2710 + (-3510)
Here we add a negative number to a positive number
2710 + -3510
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 2710 + (-3510)
Here we add a negative number to a positive number
000110112
+110111012
2710 + -3510
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 2710 + (-3510)
Here we add a negative number to a positive number
000110112
+110111012
2710 + -3510
-3510 in 2’s complement?
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 2710 + (-3510)
Here we add a negative number to a positive number
000110112
+110111012
2710 + -3510
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 2710 + (-3510)
Here we add a negative number to a positive number
000110112
+110111012
1111110002
2710 + -3510
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 2710 + (-3510)
Here we add a negative number to a positive number
000110112
+110111012
1111110002
2710 + -3510
sign
bit
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate 2710 + (-3510)
Here we add a negative number to a positive number
000110112
+110111012
1111110002
2710 + -3510
sign
bit
can you verify that this is -810 in 2’s
complement?
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate -4210 + (-110)
Here we add a negative number to a negative number
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate -4210 + (-110)
Here we add a negative number to a negative number
-4210 + -110
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate -4210 + (-110)
Here we add a negative number to a negative number
110101102
+111111112
-4210 + -110
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate -4210 + (-110)
Here we add a negative number to a negative number
110101102
+111111112
111010101
-4210 + -110
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate -4210 + (-110)
Here we add a negative number to a negative number
110101102
+111111112
1110101012
-4210 + -110
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate -4210 + (-110)
Here we add a negative number to a negative number
110101102
+111111112
1110101012
-4210 + -110
2’s Complement and Addition
since we are only using 8 bit numbers,
the ninth bit is simply dropped
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate -4210 + (-110)
Here we add a negative number to a negative number
110101102
+111111112
1110101012
-4210 + -110
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate -4210 + (-110)
Here we add a negative number to a negative number
110101102
+111111112
1110101012
-4210 + -110
sign
bit
2’s Complement and Addition
MATH1003
10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001
Calculate -4210 + (-110)
Here we add a negative number to a negative number
110101102
+111111112
1110101012
-4210 + -110
sign
bit
can you verify that this is -4310 in 2’s complement?
2’s Complement and Addition