Top Banner
MATH1003 10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001 1.15 Integers and 2’s Complement
149
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

1.15Integers and2’s Complement

Page 2: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Goal

To be able to specify how integers are stored by the computer in 2’s complement format.

Page 3: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Integers

Page 4: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Integers

Integers and Real Numbers are stored in different ways inside the computer.

Page 5: Math1003 1.15 - Integers and 2's Complement

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.

Page 6: Math1003 1.15 - Integers and 2's Complement

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

Page 7: Math1003 1.15 - Integers and 2's Complement

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

Page 8: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

35

Integers

Page 9: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Today’s computers store integers usually in 32 bits.

35

Integers

Page 10: Math1003 1.15 - Integers and 2's Complement

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

Page 11: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

35

Integers

Page 12: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

3510, as an 8 bit binary number, is 001000112

35

Integers

Page 13: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

3510, as an 8 bit binary number, is 001000112

That’s how the computer will store 3510

35

Integers

Page 14: Math1003 1.15 - Integers and 2's Complement

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

Page 15: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Sign and Magnitude

001000112signbit

Page 16: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Sign and Magnitude

How does the computer store negative numbers? (Remember: bits are only 0 or 1)

001000112signbit

Page 17: Math1003 1.15 - Integers and 2's Complement

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

Page 18: Math1003 1.15 - Integers and 2's Complement

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

Page 19: Math1003 1.15 - Integers and 2's Complement

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

Page 20: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

We’ll use the other 7 bits for the value (or magnitude) of the number.

001000112signbit

Sign and Magnitude

Page 21: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

We’ll use the other 7 bits for the value (or magnitude) of the number.

001000112magnitude

Sign and Magnitude

Page 22: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

We’ll use the other 7 bits for the value (or magnitude) of the number.

001000112magnitude

Sign and Magnitude

Page 23: Math1003 1.15 - Integers and 2's Complement

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

Page 24: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

Page 25: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

In this scheme, what is 000000002 and 100000002?

Page 26: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

In this scheme, what is 000000002 and 100000002?

000000002 is positive 0

Page 27: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

In this scheme, what is 000000002 and 100000002?

000000002 is positive 0

+0

Page 28: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

In this scheme, what is 000000002 and 100000002?

000000002 is positive 0

100000002 is negative 0

+0

Page 29: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

In this scheme, what is 000000002 and 100000002?

000000002 is positive 0

100000002 is negative 0

+0 -0

Page 30: Math1003 1.15 - Integers and 2's Complement

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

Page 31: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

+0 -0

Page 32: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

Depending on the arithmetic operation, we can get a result of 000000002 or 100000002.

+0 -0

Page 33: Math1003 1.15 - Integers and 2's Complement

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

Page 34: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

Page 35: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Problems

Another problem that arises has to do with the addition of a positive and a negative number.

Page 36: Math1003 1.15 - Integers and 2's Complement

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).

Page 37: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement

So a scheme was invented to address these issues.

It is called 2’s complement.

Page 38: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

In 2’s complement, positive numbers are represented in their normal binary equivalent.

2’s Complement

Page 39: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement

Page 40: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Negative number representation is found in the following manner:

2’s Complement

Page 41: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Negative number representation is found in the following manner:

1. calculate the magnitude of the number

2’s Complement

Page 42: Math1003 1.15 - Integers and 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

Page 43: Math1003 1.15 - Integers and 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

Page 44: Math1003 1.15 - Integers and 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

Page 45: Math1003 1.15 - Integers and 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

Page 46: Math1003 1.15 - Integers and 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

Page 47: Math1003 1.15 - Integers and 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

Page 48: Math1003 1.15 - Integers and 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

Page 49: Math1003 1.15 - Integers and 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

Page 50: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement

Page 51: Math1003 1.15 - Integers and 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

Page 52: Math1003 1.15 - Integers and 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

Page 53: Math1003 1.15 - Integers and 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

Page 54: Math1003 1.15 - Integers and 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

Page 55: Math1003 1.15 - Integers and 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

Page 56: Math1003 1.15 - Integers and 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

Page 57: Math1003 1.15 - Integers and 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

Page 58: Math1003 1.15 - Integers and 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

Page 59: Math1003 1.15 - Integers and 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

Page 60: Math1003 1.15 - Integers and 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

Page 61: Math1003 1.15 - Integers and 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

Page 62: Math1003 1.15 - Integers and 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

Page 63: Math1003 1.15 - Integers and 2's Complement

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

Page 64: Math1003 1.15 - Integers and 2's Complement

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

Page 65: Math1003 1.15 - Integers and 2's Complement

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

Page 66: Math1003 1.15 - Integers and 2's Complement

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

Page 67: Math1003 1.15 - Integers and 2's Complement

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

Page 68: Math1003 1.15 - Integers and 2's Complement

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

Page 69: Math1003 1.15 - Integers and 2's Complement

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

Page 70: Math1003 1.15 - Integers and 2's Complement

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

Page 71: Math1003 1.15 - Integers and 2's Complement

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

Page 72: Math1003 1.15 - Integers and 2's Complement

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

Page 73: Math1003 1.15 - Integers and 2's Complement

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

Page 74: Math1003 1.15 - Integers and 2's Complement

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

Page 75: Math1003 1.15 - Integers and 2's Complement

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

Page 76: Math1003 1.15 - Integers and 2's Complement

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

Page 77: Math1003 1.15 - Integers and 2's Complement

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

Page 78: Math1003 1.15 - Integers and 2's Complement

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

Page 79: Math1003 1.15 - Integers and 2's Complement

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

Page 80: Math1003 1.15 - Integers and 2's Complement

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

Page 81: Math1003 1.15 - Integers and 2's Complement

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

Page 82: Math1003 1.15 - Integers and 2's Complement

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

Page 83: Math1003 1.15 - Integers and 2's Complement

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

Page 84: Math1003 1.15 - Integers and 2's Complement

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

Page 85: Math1003 1.15 - Integers and 2's Complement

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

Page 86: Math1003 1.15 - Integers and 2's Complement

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

Page 87: Math1003 1.15 - Integers and 2's Complement

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

Page 88: Math1003 1.15 - Integers and 2's Complement

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

Page 89: Math1003 1.15 - Integers and 2's Complement

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

Page 90: Math1003 1.15 - Integers and 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

2’s Complement

Page 91: Math1003 1.15 - Integers and 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

Page 92: Math1003 1.15 - Integers and 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

Page 93: Math1003 1.15 - Integers and 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

Page 94: Math1003 1.15 - Integers and 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

Page 95: Math1003 1.15 - Integers and 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

Page 96: Math1003 1.15 - Integers and 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

Page 97: Math1003 1.15 - Integers and 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

Page 98: Math1003 1.15 - Integers and 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

Page 99: Math1003 1.15 - Integers and 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

Page 100: Math1003 1.15 - Integers and 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

Page 101: Math1003 1.15 - Integers and 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 = -910

2’s Complement this method is for negative numbers

only

Page 102: Math1003 1.15 - Integers and 2's Complement

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

Page 103: Math1003 1.15 - Integers and 2's Complement

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

Page 104: Math1003 1.15 - Integers and 2's Complement

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

Page 105: Math1003 1.15 - Integers and 2's Complement

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

Page 106: Math1003 1.15 - Integers and 2's Complement

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

Page 107: Math1003 1.15 - Integers and 2's Complement

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

Page 108: Math1003 1.15 - Integers and 2's Complement

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

Page 109: Math1003 1.15 - Integers and 2's Complement

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

Page 110: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

01011001

Page 111: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

01011001

Page 112: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

01011001

7210

+1710

Page 113: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

01011001

7210

+1710

Page 114: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

01011001

7210

+1710

Page 115: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

01011001

7210

+1710

Page 116: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

01011001

7210

+1710

Page 117: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

01011001

7210

+1710

Page 118: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

01011001

7210

+1710

Page 119: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

01011001

7210

+1710

Page 120: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

01011001

7210

+1710

Page 121: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

01011001

7210

+1710

Page 122: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

2’s Complement and Addition

Calculate 7210 + 1710

Since these are both positive, this is straightforward

010010002

+000100012

010110012

7210

+1710

Page 123: Math1003 1.15 - Integers and 2's Complement

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

Page 124: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Calculate 10410 + (-4210)

Here we add a negative number to a positive number

2’s Complement and Addition

Page 125: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Calculate 10410 + (-4210)

Here we add a negative number to a positive number

10410 + -4210

2’s Complement and Addition

Page 126: Math1003 1.15 - Integers and 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

Page 127: Math1003 1.15 - Integers and 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

-4210 in 2’s complement?

Page 128: Math1003 1.15 - Integers and 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

Page 129: Math1003 1.15 - Integers and 2's Complement

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

Page 130: Math1003 1.15 - Integers and 2's Complement

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

Page 131: Math1003 1.15 - Integers and 2's Complement

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

Page 132: Math1003 1.15 - Integers and 2's Complement

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

Page 133: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Calculate 2710 + (-3510)

Here we add a negative number to a positive number

2’s Complement and Addition

Page 134: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Calculate 2710 + (-3510)

Here we add a negative number to a positive number

2710 + -3510

2’s Complement and Addition

Page 135: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Calculate 2710 + (-3510)

Here we add a negative number to a positive number

000110112

+110111012

2710 + -3510

2’s Complement and Addition

Page 136: Math1003 1.15 - Integers and 2's Complement

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

Page 137: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Calculate 2710 + (-3510)

Here we add a negative number to a positive number

000110112

+110111012

2710 + -3510

2’s Complement and Addition

Page 138: Math1003 1.15 - Integers and 2's Complement

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

Page 139: Math1003 1.15 - Integers and 2's Complement

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

Page 140: Math1003 1.15 - Integers and 2's Complement

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

Page 141: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Calculate -4210 + (-110)

Here we add a negative number to a negative number

2’s Complement and Addition

Page 142: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Calculate -4210 + (-110)

Here we add a negative number to a negative number

-4210 + -110

2’s Complement and Addition

Page 143: Math1003 1.15 - Integers and 2's Complement

MATH1003

10110100101011010100101010111010101111011011101111011101110111101110111011110111111010110100101011110110110101111011010100111111011010100110101001

Calculate -4210 + (-110)

Here we add a negative number to a negative number

110101102

+111111112

-4210 + -110

2’s Complement and Addition

Page 144: Math1003 1.15 - Integers and 2's Complement

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

Page 145: Math1003 1.15 - Integers and 2's Complement

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

Page 146: Math1003 1.15 - Integers and 2's Complement

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

Page 147: Math1003 1.15 - Integers and 2's Complement

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

Page 148: Math1003 1.15 - Integers and 2's Complement

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

Page 149: Math1003 1.15 - Integers and 2's Complement

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