Top Banner
Binary Review Lecture 2 Section 2.4 Robb T. Koether Hampden-Sydney College Wed, Aug 28, 2019 Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 1 / 40
44

Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Aug 13, 2020

Download

Documents

dariahiddleston
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: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary ReviewLecture 2

Section 2.4

Robb T. Koether

Hampden-Sydney College

Wed, Aug 28, 2019

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 1 / 40

Page 2: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 2 / 40

Page 3: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 3 / 40

Page 4: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 4 / 40

Page 5: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary review

When studying the processor at the hardware level we need todeal with binary numbers.Binary has two symbols: 0 and 1.A binary symbol is called a bit.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 5 / 40

Page 6: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary review

Bits are grouped to store more information.1 nibble = 4 bits.1 byte = 8 bits.1 halfword = 2 bytes = 16 bits.1 word = 4 bytes = 32 bits.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 6 / 40

Page 7: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary review

It is confusing to look at strings of 0s and 1s.1111111111111111111111111111111111111110000011111111000001111111111111100000111111110000011111111111111000001111111100000111111111111111111111111111111111111111111111111111111111111111111111111111000111111111111111111000111111110000000111111111100000001111111111100000000000000000011111111111111111100000000001111111111111111111111111111111111111111111

The problem is too many of the same symbol.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 7 / 40

Page 8: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary review

Let one symbol represent a group of bits.1-bit can represent 2 different things.2-bits can represent 4 different things.3-bits can represent 8 different things.4-bits can represent 16 different things.

In general, n-bits can represent 2n different things.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 8 / 40

Page 9: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary review

Four bits (half a byte) represent sixteen things.Hexadecimal consists of 16 different symbols.0, . . . , 9, A, B, C, D, E, F.

Binary Hex Symbol Binary Hex Symbol0000 0 1000 80001 1 1001 90010 2 1010 A0011 3 1011 B0100 4 1100 C0101 5 1101 D0110 6 1110 E0111 7 1111 F

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 9 / 40

Page 10: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary review

To convert from binary to hexadecimalGroup bits in fours from the right end of the string. (Add leading 0sif necessary.)Substitute the corresponding hexadecimal digit.

11111010110011102 = 11112 | 10102 | 11002 | 11102

= F | A | C | E= FACE16.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 10 / 40

Page 11: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary review

To convert from hexadecimal to binary, reverse the process.

FACE16 = F | A | C | E= 11112 | 10102 | 11002 | 11102

= 11111010110011102

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 11 / 40

Page 12: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 12 / 40

Page 13: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Storing Negative Integers

To store negative integers, we divide the range 0 to 232− 1 in half.The lower half 0 to 231 − 1 (hex 00000000 to hex 7FFFFFFF)represents the positive integers 0 to 231 − 1.The upper half 231 to 232 − 1 (hex 80000000 to hex FFFFFFFF)represents the negative integers.

Negative integers are interpreted in two’s complement notation.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 13 / 40

Page 14: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

3-Bit Signed and Unsigned Integers

Unsigned000 0001 1010 2011 3100 4101 5110 6111 7

Signed000 0001 1010 2011 3100 −4101 −3110 −2111 −1

3-bit integers, unsigned and signed

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 14 / 40

Page 15: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

3-Bit Unsigned Integers

Unsigned00000000000000000000000000000000 000000000000000000000000000000001 100000000000000000000000000000010 2

: :01111111111111111111111111111111 231 − 110000000000000000000000000000000 231

10000000000000000000000000000001 231 + 110000000000000000000000000000010 231 + 2

: :11111111111111111111111111111111 232 − 1

32-bit unsigned integers

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 15 / 40

Page 16: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

3-Bit Signed Integers

Signed00000000000000000000000000000000 000000000000000000000000000000001 100000000000000000000000000000010 2

: :01111111111111111111111111111111 231 − 110000000000000000000000000000000 −231

10000000000000000000000000000001 −231 + 110000000000000000000000000000010 −231 + 2

: :11111111111111111111111111111111 −1

32-bit signed integers

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 16 / 40

Page 17: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

3-Bit Signed and Unsigned Integers

Unsigned

00000000000000000000000000000000 000000000000000000000000000000001 100000000000000000000000000000010 2

: :01111111111111111111111111111111 231 − 110000000000000000000000000000000 231

10000000000000000000000000000001 231 + 110000000000000000000000000000010 231 + 2

: :11111111111111111111111111111111 232 − 1

Signed

00000000000000000000000000000000 000000000000000000000000000000001 100000000000000000000000000000010 2

: :01111111111111111111111111111111 231 − 110000000000000000000000000000000 −231

10000000000000000000000000000001 −231 + 110000000000000000000000000000010 −231 + 2

: :11111111111111111111111111111111 −1

32-bit integers, unsigned and signed

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 17 / 40

Page 18: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Two’s Complement

Negative integers are interpreted in two’s complement notation.The 1 in bit 31 (MSB) indicates a negative integer.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 18 / 40

Page 19: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

3-Bit Signed and Unsigned Integers

Unsigned000 0001 1010 2011 3100 4101 5110 6111 7

Signed000 0001 1010 2011 3100 −4101 −3110 −2111 −1

3-bit integers, unsigned and signed

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 19 / 40

Page 20: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Two’s Complement Example

Example (Two’s Complement Example)The absolute value of the negative integer (i.e., the correspondingpositive integer) is obtained by reversing all the bits and thenadding 1.

What negative number is represented by1111 1111 1111 1111 1111 0000 1100 1110?

Reverse all the bits:0000 0000 0000 0000 0000 1111 0011 0001

Add 1:0000 0000 0000 0000 0000 1111 0011 0010

The value is −3890.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 20 / 40

Page 21: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Two’s Complement Example

Example (Two’s Complement Example)The absolute value of the negative integer (i.e., the correspondingpositive integer) is obtained by reversing all the bits and thenadding 1.What negative number is represented by

1111 1111 1111 1111 1111 0000 1100 1110?

Reverse all the bits:0000 0000 0000 0000 0000 1111 0011 0001

Add 1:0000 0000 0000 0000 0000 1111 0011 0010

The value is −3890.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 20 / 40

Page 22: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Two’s Complement Example

Example (Two’s Complement Example)The absolute value of the negative integer (i.e., the correspondingpositive integer) is obtained by reversing all the bits and thenadding 1.What negative number is represented by

1111 1111 1111 1111 1111 0000 1100 1110?Reverse all the bits:

0000 0000 0000 0000 0000 1111 0011 0001

Add 1:0000 0000 0000 0000 0000 1111 0011 0010

The value is −3890.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 20 / 40

Page 23: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Two’s Complement Example

Example (Two’s Complement Example)The absolute value of the negative integer (i.e., the correspondingpositive integer) is obtained by reversing all the bits and thenadding 1.What negative number is represented by

1111 1111 1111 1111 1111 0000 1100 1110?Reverse all the bits:

0000 0000 0000 0000 0000 1111 0011 0001

Add 1:0000 0000 0000 0000 0000 1111 0011 0010

The value is −3890.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 20 / 40

Page 24: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Two’s Complement Example

Example (Two’s Complement Example)The absolute value of the negative integer (i.e., the correspondingpositive integer) is obtained by reversing all the bits and thenadding 1.What negative number is represented by

1111 1111 1111 1111 1111 0000 1100 1110?Reverse all the bits:

0000 0000 0000 0000 0000 1111 0011 0001

Add 1:0000 0000 0000 0000 0000 1111 0011 0010

The value is −3890.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 20 / 40

Page 25: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 21 / 40

Page 26: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary Arithmetic

Perform the following additions as 8-bit unsigned integers;00001011+ 0000011011110001+ 0000010111110001+ 11111101

In which case(s) was there overflow?How is overflow detected?

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 22 / 40

Page 27: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary Arithmetic

Perform the following additions as 8-bit signed integers;00001011+ 0000011001111011+ 0111011011110001+ 0000010111110001+ 1111110110000111+ 10001101

In which case(s) was there overflow?How is overflow detected?

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 23 / 40

Page 28: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary Arithmetic

Subtraction is performed by adding the two’s complement of thesubtrahend.Perform the following subtractions as 8-bit unsigned integers;

00001111− 0000011000000011− 00000110

In which case(s) was there overflow?How is overflow detected?

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 24 / 40

Page 29: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Binary Arithmetic

Perform the following subtractions as 8-bit signed integers;00001111− 0000011000000011− 0000011001111100− 1111011010000101− 00001110

In which case(s) was there overflow?How is overflow detected?

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 25 / 40

Page 30: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 26 / 40

Page 31: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 27 / 40

Page 32: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Unsigned Addition Overflow

x y x + yMSB MSB MSB Overflow?

0 0 0 No0 0 1 No0 1 0 Yes0 1 1 No1 0 0 Yes1 0 1 No1 1 0 Yes1 1 1 Yes

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 28 / 40

Page 33: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Unsigned Addition Overflow

x y x + yMSB MSB MSB Overflow?

0 0 0 No0 0 1 No0 1 0 Yes0 1 1 No1 0 0 Yes1 0 1 No1 1 0 Yes1 1 1 Yes

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 29 / 40

Page 34: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 30 / 40

Page 35: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Unsigned Subtraction Overflow

x y x − yMSB MSB MSB Overflow?

0 0 0 No0 0 1 Yes0 1 0 Yes0 1 1 Yes1 0 0 No1 0 1 No1 1 0 No1 1 1 Yes

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 31 / 40

Page 36: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Unsigned Subtraction Overflow

x y x − yMSB MSB MSB Overflow?

0 0 0 No0 0 1 Yes0 1 0 Yes0 1 1 Yes1 0 0 No1 0 1 No1 1 0 No1 1 1 Yes

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 32 / 40

Page 37: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 33 / 40

Page 38: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Signed Addition Overflow

x y x + yMSB MSB MSB Overflow?

0 0 0 No0 0 1 Yes0 1 0 No0 1 1 No1 0 0 No1 0 1 No1 1 0 Yes1 1 1 No

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 34 / 40

Page 39: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Signed Addition Overflow

x y x + yMSB MSB MSB Overflow?

0 0 0 No0 0 1 Yes0 1 0 No0 1 1 No1 0 0 No1 0 1 No1 1 0 Yes1 1 1 No

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 35 / 40

Page 40: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 36 / 40

Page 41: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Signed Subtraction Overflow

x y x − yMSB MSB MSB Overflow?

0 0 0 No0 0 1 No0 1 0 No0 1 1 Yes1 0 0 Yes1 0 1 No1 1 0 No1 1 1 No

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 37 / 40

Page 42: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Signed Subtraction Overflow

x y x − yMSB MSB MSB Overflow?

0 0 0 No0 0 1 No0 1 0 No0 1 1 Yes1 0 0 Yes1 0 1 No1 1 0 No1 1 1 No

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 38 / 40

Page 43: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Outline

1 Binary ReviewBinary NumbersSigned IntegersBinary Arithmetic

2 Detecting OverflowUnsigned Addition OverflowUnsigned Subtraction OverflowSigned Addition OverflowSigned Subtraction Overflow

3 Assignment

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 39 / 40

Page 44: Binary Review - Lecture 2 Section 2 - people.hsc.edupeople.hsc.edu/faculty-staff/robbk/Coms361/Lectures... · 2019-08-30 · 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101

Assignment

AssignmentRead Section 2.4.

Robb T. Koether (Hampden-Sydney College) Binary Review Wed, Aug 28, 2019 40 / 40