Top Banner
Integers
23

Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

Dec 16, 2015

Download

Documents

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: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

Integers

Page 2: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

Integer Storage

Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers.

Instead, the Most Significant Bit is used to represent the sign.

This way, half the combinations in a fixed length of bits can be used to represent negative values.

But which value of the sign bit (0 or 1) will represent a negative number?

Page 3: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

Integers

2’s Complement Notation

Page 4: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation(examples in 8 bits to save space)

Fixed length notation system.

Uses 1 to represent negative values.

Since 1 is always greater than 0, the largest non-negative value: 01111111 the smallest non-negative value: 00000000 the largest negative value: 11111111 the smallest negative value: 10000000

Page 5: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation(examples in 8 bits to save space)

What is the decimal equivalent of these?

The largest non-negative value: 01111111

The smallest non-negative value: 00000000

The largest negative value: 11111111

The smallest negative value: 10000000

Page 6: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation(examples in 8 bits to save space)

What is the decimal equivalent of these?

The largest non-negative value: 01111111

+127 The smallest non-negative value: 00000000

The largest negative value: 11111111

The smallest negative value: 10000000

Page 7: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation(examples in 8 bits to save space)

What is the decimal equivalent of these?

The largest non-negative value: 01111111

+127 The smallest non-negative value: 00000000

+0 The largest negative value: 11111111

The smallest negative value: 10000000

Page 8: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation(examples in 8 bits to save space)

What is the decimal equivalent of these?

The largest non-negative value: 01111111

+127 The smallest non-negative value: 00000000

+0 The largest negative value: 11111111

-1 The smallest negative value: 10000000

Page 9: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation(examples in 8 bits to save space)

What is the decimal equivalent of these?

The largest non-negative value: 01111111

+127 The smallest non-negative value: 00000000

+0 The largest negative value: 11111111

-1 The smallest negative value: 10000000

-128

Page 10: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

The representations of non-negative integers in 2’s Complement look the same as they do for Natural numbers.

However, negative values look VERY different than we might expect.

Page 11: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

Complementary numbers sum to 0. Decimal is a Signed Magnitude system so

complements have the same magnitude but different signs: 5 and -5, for example.

2’s Complement is a Fixed Length system. There are no signs, so to find a number’s complement, another technique is needed.

Page 12: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

One such technique is to simply change each bit to its opposite, and then add 1.

Page 13: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

One such technique is to simply change each bit to its opposite, and then add 1.

To find the 2’s complement notation for -5:

Page 14: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

One such technique is to simply change each bit to its opposite, and then add 1.

To find the 2’s complement notation for -5:

Represent +5 in fixed length

Page 15: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

One such technique is to simply change each bit to its opposite, and then add 1.

To find the 2’s complement notation for -5:

Represent +5 in fixed length 00000101

Page 16: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

One such technique is to simply change each bit to its opposite, and then add 1.

To find the 2’s complement notation for -5:

Represent +5 in fixed length 00000101

“flip the bits” (1 → 0, 0 → 1)

Page 17: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

One such technique is to simply change each bit to its opposite, and then add 1.

To find the 2’s complement notation for -5:

Represent +5 in fixed length 00000101

“flip the bits” (1 → 0, 0 → 1) 11111010

Page 18: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

One such technique is to simply change each bit to its opposite, and then add 1.

To find the 2’s complement notation for -5:

Represent +5 in fixed length 00000101

“flip the bits” (1 → 0, 0 → 1) 11111010

add 1 to the new pattern +1

Page 19: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

One such technique is to simply change each bit to its opposite, and then add 1.

To find the 2’s complement notation for -5:

Represent +5 in fixed length 00000101

“flip the bits” (1 → 0, 0 → 1) 11111010

add 1 to the new pattern +1

to produce -5 11111011

Page 20: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

Complementary numbers sum to 0.

Page 21: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

Complementary numbers sum to 0.

So if to +5 00000101

Page 22: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

Complementary numbers sum to 0.

So if to +5

we add -5

00000101

+11111011

Page 23: Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.

2’s Complement Notation

Complementary numbers sum to 0.

So if to +5

we add -5

we should get

00000101

+11111011

1 00000000discard the carry bit to retain the fixed length