boolean algebra binary arithmetic august 28, 2001 ellen spertus mcs 111

24
Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

Upload: charles-black

Post on 18-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

Boolean AlgebraBinary Arithmetic

August 28, 2001

Ellen Spertus

MCS 111

Page 2: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

2

What you will learn this semester

• Given devices that implement simple boolean functions…

• Understand how a computer works– Build an actual computer that you will

program– Study the MIPS architecture

• Write assembly language programs• Learn the implementation of a MIPS subset

Page 3: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

3

How you will learn

• Readings

• Lectures and discussion

• Homework assignments to review lecture material

Lab assignments to apply ideas in depth (every 2-3 weeks)

Page 4: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

4

Boolean algebra

• George Boole (1815-1864)

• What is an algebra?

• Boolean values

• Boolean operations

• Boolean functions

Page 5: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

5

What is an algebra?

• Term from Hisab al-jabr w'al-muqabala by al-Khwarizmi (~780-850, Baghdad)

• Consists of– a set of values

(e.g., the integers)– a set of functions

• multiplication• addition

Page 6: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

6

Expressing functions• What’s a function?

• What are these functions?• Why is this a bad way of expressing a function over the integers?

inputs outputs x f(x) x y f(x, y) 0 1 1 1 1 1 2 2 1 2 2 3 3 2 4 3 4 4 2 5 : : : : :

Page 7: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

7

Boolean values

• false • 0• low

• true • 1• high

Page 8: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

8

Boolean operations

• identity

• not

• or

• and

• xor (exclusive or)

• nand (not and)

• nor (not or)

Page 9: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

9

Identity

x x 0 1

0

Note: Bebop calls this “buf” (for “buffer”).

Page 10: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

10

Not

x x 0 1

0

Note: Some people write x’ instead of x. The “bubble” (or “bobble”) means “not”.

Page 11: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

11

And

a b a·b 0 0 0 1 1 0 1 1

Notes: Some people write a^b or a&b. The gate is shaped like a “D” as in “anD”.

and01

Page 12: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

12

Or

a b a+b 0 0 0 1 1 0 1 1

Note: Some people write ab or a|b.

0

1or

1or

1

Page 13: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

13

Exclusive-or (xor)

a b ab 0 0 0 1 1 0 1 1

0

1

1

1

Page 14: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

14

Nand

a b a·b a·b 0 0 0 0 1 0 1 0 0 1 1 1

Page 15: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

15

Nor

a b a+b a+b 0 0 0 0 1 1 1 0 1 1 1 1

Page 16: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

16

What you will learn

• Given devices that implement simple boolean functions…

• Understand how a computer works

Page 17: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

17

Base-10 (decimal) arithmetic

• Uses the ten numbers from 0 to 9

• Each column represents a power of 10

Thousands (10 3) column

Hundreds (10 2) column

Tens (10 1) column

Ones (10 0) column

1999 10= 1x10 3 + 9x10 2 + 9x10 1 + 9x10 0

Page 18: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

18

Base-2 (binary) arithmetic

• Uses the two numbers from 0 to 1

• Every column represents a power of 2

10012= 1x2 3 + 0x2 2 + 0x2 1 + 1x2 0

Eights (2 3) column

Fours (2 2) column

Twos (2 1) column

Ones (2 0) column

Page 19: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

19

Converting from base-2 to base-10

32 16 8 4 2 1 1 0 0 1 = 1 0 1 1 = 1 0 1 0 1 =

1 1 1 1 1 1 =

Page 20: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

20

Converting from base-10 to base-2

64 32 16 8 4 2 1 = 16 = 55 = 75 = 84

Page 21: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

21

Addition

1 9 9 8 1 0 1 1 + 1 1 + 1 1 2 0 0 9 1 1 1 0

Base-10 Base-2

Note: A binary digit is called a bit. The bit with the lowest exponent (20) is called the least significant bit (LSB). The bit with the highest exponent is the most significant bit (MSB).

Page 22: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

22

Practice binary arithmetic

1 0 1 1 1 1 1 + 1 1 + 1

Page 23: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

23

Count on your fingers!

How high can you count with– 5 fingers?– 10 fingers?

Page 24: Boolean Algebra Binary Arithmetic August 28, 2001 Ellen Spertus MCS 111

24

Looking ahead

• For you to do– Complete and turn in information form– Read syllabus and policies– Homework, due Tuesday, September 4

• Coming up – Thursday: Digital computing– Next week: First lab sessions