42
WEEK 2 Number Systems & Boolean Algebra 1

SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

  • Upload
    others

  • View
    7

  • Download
    1

Embed Size (px)

Citation preview

Page 1: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

WEEK 2 Number Systems & Boolean Algebra

1

Page 2: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Number Representation (Recall)

2

Page 3: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

3

Addition (Unsigned Numbers)

Binary addition of unsigned numbers is done just like in decimal. Add digits and generate carries

Important: We can get a non-zero

carry out; if we are limited to n-bits,

this becomes an overflow condition

Page 4: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

4

Subtraction (Unsigned Numbers) Binary subtraction is also similar to decimal

subtraction. Use borrow when needed

Important: Doesn’t seem to work if

second term is larger!! A negative result

is often considered an underflow

Page 5: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

5

Subtraction (Unsigned Numbers) Using r’s Complement

Page 6: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

6

Subtraction …Examples

10’s complement subtraction

A = 72532, A’ = 27468

B = 03250, B’ = 96750

A – B = 72532 B – A = 03250

+ 96750 + 27468

1 69282 30718 - 69282

Minuend is greater than

Subtrahend discard carry Minuend is less than subtrahend

10’s comp the result

and add negative sign

10’s comp

Page 7: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

7

Subtraction …Examples

2’s complement subtraction

A = 1010100, A’ = 0101100

B = 1000100, B’ = 0111100

A – B = 1010100 B – A = 1000100

+ 0111100 + 0101100

1 0010000 1110000

2’s comp - 0010000

Minuend is greater than

Subtrahend discard carry Minuend is less than subtrahend

10’s comp the result

and add negative sign

Page 8: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

8

Subtraction r-1 complement …Examples

9’s complement subtraction

A = 72532, A’ = 27467

B = 03250, B’ = 96749

A – B = 72532 B – A = 03250

+ 96749 + 27467

1 69281 30717 - 69282 + 00001

69282

Page 9: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

9

Subtraction …Examples

1’s complement subtraction

A = 1010100, A’ = 0101011

B = 1000100, B’ = 0111011

A – B = 1010100 B – A = 1000100

+ 0111011 + 0101011

1 0010000 1101111

0000001 - 0010000 0010001

Page 10: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

10

Radix Conversion The integral part of a decimal number to radix r,

repeatedly divide by r with reminders becoming ai

Convert (77)10 to binary

Integer Remainder Coefficient

77

38 1 a0

19 0 a1

9 1 a2

4 1 a3

2 0 a4

1 0 a5

0 1 a6

(77)10 = (1001101)2

Page 11: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

11

Examples Convert (173)10 to r = 7

Integer Remainder Coefficient

173

24 5 a0

3 3 a1

0 3 a2

(173)10 = (335)7

Converting from Binary to decimal

(101101)2 = 1x25 + 0x24 + 1x23 + 1x22 +0x21 +1x20 =

(45)10

Page 12: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

12

Fraction Conversion

To convert the fractional part of a number to radix r,

repeatedly multiply by r; integral parts of products

becoming ai

Convert (0.7215)10 to binary

0.7215x2 = 1.443 a-1 = 1

0.443x2 = 0.866 a-2 = 0

0.866x2 = 1.772 a-3 =1

0.772x2 = 1.544 a-4 = 1

0.544 = 1.088 a-5 = 1

(0.7215)10 = (0.10111..)2

Page 13: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

13

5 bit word (1 for sign, 4 for values)

-2+3=1

1|1110

+0|0011

0|0001

There is a carry, value is answer

7-9=-2

0|0111

+ 1|0111

0|1110

no carry value is 2scomp of answer

Answer (-) 2scomp of 1110- 0010

-5-(-3)=-2

1|1011

+0|0011

0|1110

No carry answer=(-) 2s comp of 1110=- 0010

More Examples: Binary

Page 14: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

14

323-121=202

0|323

0|879

1|202

Carry value is answer

323-532=-219

0|323

0|468

0|781

No carry value is (-)10s comp of answer

10scom - 219

111-888=-777

0|111

0|112

0|223

No carry value is (-)10s comp of answer, 10s comp -777

More Examples: Decimal

Page 15: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

15

Codes Decimal numbers are coded using binary bit patterns

Decimal BCD (8421) 2421 Excess-3 Gray

0 0000 0000 0011 0000

1 0001 0001 0100 0001

2 0010 0010 0101 0011

3 0011 0011 0110 0010

4 0100 0100 0111 0110

5 0101 0101 1000 0111

6 0110 0110 1001 0101

7 0111 0111 1010 0100

8 1000 1110 1011 1100

9 1001 1111 1100 1101

SELF-COMPLEMENTING

ONLY ONE BIT

ALLOWED TO CHANGE 9=2+4+2+1

Page 16: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

16

More on Codes

BCD

Self-complementing code: Code word of 9’s complement of N obtained

by interchanging 1’s and 0’s in the code word of N

Self-complementing Codes

N=1011=5, 9’s complement is 4=0100=1’s comp of 1011

Page 17: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

17

BCD Addition

BCD addition can be carried out as follows:

4 0100 8 1000

+8 +1000 +9 +1001

12 1100 17 10001

Add 6 0110 0110

BCD 00010010 1 0111

Page 18: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

18

Complements, Signed Arithmetic, Codes - Book Sections

Complements and Signed Arithmetic are covered in Chapter 1, Sections 1.5 through 1.7

Page 19: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 19

Binary Logic

Binary (Boolean) logic deals with binary variables and binary logic functions.

By binary, we means they can take on two discrete values. “0” means OPEN, NO, FALSE.

“1” means CLOSED, YES, TRUE.

Logic functions (expressions) produce an output as some logical function of its inputs.

Page 20: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 20

Truth Tables

We can define a logic function using a truth table.

The truth table tells us the value of the function for each possible set of input values.

Binary variable

f(x,y): binary function

f(x,y) is 1 if x and y are 00 or 11.

That is (Not(x) and Not(y)) OR (X and Y)

f(x,y)=x’.y’+x.y

Page 21: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 21

Basic Logical Operations

Three basic logical operations:

AND/OR/NOT.

NOT also called COMPLEMENT or INVERTER

Page 22: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 22

Precedence of Operations

Precedence of operations:

(), then

NOT, then

AND, then

OR

Introduce () to help clarify precedence.

f(x,y,z)=Not(x).y+z= (Not(x) and y) or z

f(x,y,z)=(x+z).y+x=(x or z) and (y or x)

Page 23: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 23

Logic Gates and Symbols

In reality, logic functions are implemented via logic gates.

We have symbols to represent the different logic functions visually (e.g., In a schematic diagram).

Logic gates are implemented via transistors.

Page 24: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 24

Logic Function and Symbol for

AND (2-input) Binary variable

f(x,y): binary function

f = x.y

f = x&y

Page 25: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 25

Logic Function and Symbol for

OR (2-input)

Page 26: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 26

Logic Function and Symbol for

NOT (1-input only/always)

Page 27: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

How many logical functions? 7, one function for each segment.

b1,b2,b3,b4

e,g

1010

Page 27

Page 28: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 28

b1 b2 b3 b4

Page 29: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 29

b1 b2 b3 b4

Logical Expressions

A=(b1’b2’b3’b4’)+

(b1’b2’b3b4’)+

(b1’b2’b3b4)+

(b1’b2b3’b4)+

(b1’b2b3b4’)+

(b1’b2b3b4)+

(b1b2’b3’b4’)+

(b1b2’b3’b4)+

(b1b2’b3b4’)

(b1b2b3’b4’)+

(b1b2b3b4’)+

(b1b2b3b4)

A’=(b1’b2’b3’b4)+(b1’b2b3’b4’)+(b1b2’b3b4)+

(b1b2b3’b4)

1

Derive expressions for B to G

Page 30: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 30

Multiple Input Logic Gates

AND/OR can have any number of inputs. Meaning is understood.

Output of n-input AND gate is 1 when every input is 1, otherwise 0.

Output of n-input OR gate is 1 when any input is 1, otherwise 0.

Page 31: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 31

Just to be clear…

Can show the truth tables for 3-input

AND/OR gates:

Simple Question: Given n-inputs, how many possible input combinations are there?

Page 32: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 32

Textbook Sections

Material introducing binary logic is in

Chapter 1, Section 1.9 of the textbook.

Page 33: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 33

Boolean Algebra

Provides a means of manipulating Boolean

logic functions.

Introduced by George Boole in 1854.

Shown to be useful/applicable to electrical

switching circuits by C. E. Shannon in 1938.

Page 34: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Boolean Algebra Postulate 1: Set and Operators

Define a set K containing two or more elements.

Define two binary operators:

+, also called “OR”

·, also called “AND”

Such that for any pair of elements, a and b in K, a + b and a·b also belong to K

Page 35: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Postulate 2: Identity Elements

There exist 0 and 1 elements in K, such that for every element a in K

a + 0 = a

a · 1 = a

Definitions:

0 is the identity element for + operation

1 is the identity element for · operation

Remember, 0 and 1 here should not be misinterpreted as 0 and 1 of ordinary algebra.

Page 36: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Postulate 3: Commutativity

Binary operators + and · are commutative.

That is, for any elements a and b in K:

a + b = b + a

a · b = b · a

Page 37: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Postulate 4: Associativity

Binary operators + and · are associative.

That is, for any elements a, b and c in K:

a + (b + c) = (a + b) + c

a · (b · c) = (a · b) · c

Page 38: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Postulate 5: Distributivity

Binary operator + is distributive over · and · is distributive over +.

That is, for any elements a, b and c in K:

a + (b · c) = (a + b) · (a + c)

a · (b + c) = (a · b) + (a · c)

Remember dot (·) operation is performed before + operation:

a + b · c = a + ( b · c) ≠ (a + b) · c

Page 39: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Postulate 6: Complement

A unary operation, complementation, exists for every element of K.

That is, for any elements a in K:

0aa

1aa

Page 40: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 40

Axioms/Postulates of Boolean

Algebra Continued Using the definitions of AND/OR and NOT

functions, we can show all the postulates

are satisfied.

Note: Postulates are facts that can be taken as true; they do not require proof.

Page 41: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 41

Theorems and Properties of

Boolean Algebra Theorems help us out in manipulating

Boolean expressions.

They must be proven from the postulates and/or

other theorems known to be proven correct.

Note: duality in relationships if we interchange + with ² and 0 with 1.

Page 42: SRAM Decoders and Architecturespami.uwaterloo.ca/~basir/ECE124/week2.pdf · 2011-01-20 · 2’s complement subtraction A = 1010100, A’ = 0101100 B = 1000100, B’ = 0111100 A –

Page 42

Use of Boolean Algebra

We can use the postulates and theorems to

simplify expressions, to prove equivalence

of expressions, etc.