126
Boolean Algebra

Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Boolean Algebra

Page 2: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Introduction

• 1854: Logical algebra was published by George Boole known today as “Boolean Algebra”

– It’s a convenient way and systematic way of expressing and analyzing the operation of logic circuits.

• 1938: Claude Shannon was the first to apply Boole’s work to the analysis and design of logic circuits.

Page 3: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Boolean Operations & Expressions

• Variable – a symbol used to represent a logical quantity.

• Complement – the inverse of a variable and is indicated by a bar over the variable.

• Literal – a variable or the complement of a variable.

Page 4: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Boolean Addition

• Boolean addition is equivalent to the OR operation

• A sum term is produced by an OR operation with no AND ops involved. – i.e. A B, A B, A B C , A B C D

– A sum term is equal to 1 when one or more of the literals in the term are 1.

– A sum term is equal to 0 only if each of the literals is 0.

0+0 = 0 0+1 = 1 1+0 = 1 1+1 = 1

Page 5: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

0·0 = 0 0·1 = 0 1·0 = 0 1·1 = 1

Boolean Multiplication

• Boolean multiplication is equivalent to the AND operation

• A product term is produced by an AND operation with

no OR ops involved. – i.e. AB, AB, ABC , ABCD – A product term is equal to 1 only if each of the literals in

the term is 1. – A product term is equal to 0 when one or more of the

literals are 0.

Page 6: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Commutative Laws

• The commutative law of addition for two variables is written as: A+B = B+A

A A+B

B

B B+A

A

• The commutative law of multiplication for two variables is written as: AB = BA

A AB

B

B B+A

A

Page 7: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Associative Laws

B+C

A+B

BC

AB

• The associative law of addition for 3 variables is written as: A+(B+C) = (A+B)+C

A A+(B+C)

B

C

A

B (A+B)+C

C

• The associative law of multiplication for 3 variables is written as: A(BC) = (AB)C

A A(BC)

B

C

A

B (AB)C

C

Page 8: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Distributive Laws

B+C AB

AC

• The distributive law is written for 3 variables as follows: A(B+C) = AB + AC

B A

C B X

A X

A

C

X=A(B+C) X=AB+AC

Page 9: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Rules of Boolean Algebra

1.A 0 A 7.A A A

2.A 1 1 8.A A 0

3.A 0 0

9.A A

4.A 1 A 10.A AB A

5.A A A 11.A AB A B

6.A A 1 12.( A B)( A C) A BC

___________________________________________________________

A, B, and C can represent a single variable or a combination of variables.

Page 10: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

DeMorgan’s Theorems

• DeMorgan’s theorems provide mathematical verification of:

– the equivalency of the NAND and negative-OR gates

– the equivalency of the NOR and negative-AND gates.

Page 11: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

DeMorgan’s Theorems

• The complement of two or more ANDed variables is equivalent to the OR of the complements of the individual variables.

• The complement of two or

more ORed variables is equivalent to the AND of the complements of the individual variables.

NOR

X Y

NAND

X Y

Negative-OR

X Y

Negative-AND

X Y

Page 12: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

DeMorgan’s Theorems (Exercises)

• Apply DeMorgan’s theorems to the expressions:

X Y Z

X Y Z

X Y Z

W X Y Z

Page 13: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

DeMorgan’s Theorems (Exercises)

• Apply DeMorgan’s theorems to the expressions:

( A B C)D

ABC DEF

AB CD EF

A BC D(E F )

Page 14: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Boolean Analysis of Logic Circuits

• Boolean algebra provides a concise way to express the operation of a logic circuit formed by a combination of logic gates

– so that the output can be determined for various combinations of input values.

Page 15: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

CD

B+CD

Boolean Expression for a Logic Circuit

• To derive the Boolean expression for a given logic circuit, begin at the left-most inputs and work toward the final output, writing the expression for each gate.

C

D

B

A A(B+CD)

Page 16: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Constructing a Truth Table for a Logic Circuit

• Once the Boolean expression for a given logic circuit has been determined, a truth table that shows the output for all possible values of the input variables can be developed.

– Let’s take the previous circuit as the example:

A(B+CD)

– There are four variables, hence 16 (24) combinations of values are possible.

Page 17: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Constructing a Truth Table for a Logic Circuit

• Evaluating the expression

– To evaluate the expression A(B+CD), first find the values of the variables that make the expression equal to 1 (using the rules for Boolean add & mult).

– In this case, the expression equals 1 only if A=1 and B+CD=1 because

A(B+CD) = 1·1 = 1

Page 18: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Constructing a Truth Table for a Logic Circuit

• Evaluating the expression (cont’)

– Now, determine when B+CD term equals 1.

– The term B+CD=1 if either B=1 or CD=1 or if both B and CD equal 1 because

B+CD = 1+0 = 1

B+CD = 0+1 = 1

B+CD = 1+1 = 1

• The term CD=1 only if C=1 and D=1

Page 19: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Constructing a Truth Table for a Logic Circuit

• Evaluating the expression (cont’)

– Summary:

– A(B+CD)=1

• When A=1 and B=1 regardless of the values of C and D

• When A=1 and C=1 and D=1 regardless of the value of B

– The expression A(B+CD)=0 for all other value combinations of the variables.

Page 20: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Constructing a Truth Table for a Logic Circuit

INPUTS OUTPUT

A B C D A(B+CD)

0 0 0 0

0 0 0 1

0 0 1 0

0 0 1 1

0 1 0 0

0 1 0 1

0 1 1 0

0 1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

1 0 1 1

1 1 0 0

1 1 0 1

1 1 1 0

1 1 1 1

INPUTS OUTPUT

A B C D A(B+CD)

0 0 0 0

0 0 0 1

0 0 1 0

0 0 1 1

0 1 0 0

0 1 0 1

0 1 1 0

0 1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

1 0 1 1

1 1 0 0 1

1 1 0 1 1

1 1 1 0 1

1 1 1 1 1

INPUTS OUTPUT

A B C D A(B+CD)

0 0 0 0

0 0 0 1

0 0 1 0

0 0 1 1

0 1 0 0

0 1 0 1

0 1 1 0

0 1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

1 0 1 1 1

1 1 0 0 1

1 1 0 1 1

1 1 1 0 1

1 1 1 1 1

• Putting the results in truth table format

A(B+CD)=1

When A=1 and

B=1 regardless

of the values

of C and D When A=1 and C=1 and D=1 regardless of

the value of B

INPUTS OUTPUT

A B C D A(B+CD)

0 0 0 0 0

0 0 0 1 0

0 0 1 0 0

0 0 1 1 0

0 1 0 0 0

0 1 0 1 0

0 1 1 0 0

0 1 1 1 0

1 0 0 0 0

1 0 0 1 0

1 0 1 0 0

1 0 1 1 1

1 1 0 0 1

1 1 0 1 1

1 1 1 0 1

1 1 1 1 1

Page 21: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Distinction between analog and digital signal

Analog signal

• Analog signal is a continuous signal

• Denoted by sine wave

• Stored in the form of wave signal

• Analog instrument draws large

power

• Low cost and portable

Digital signal

• Digital signals are discrete time

signals

• Denoted by square waves

• Stored in the form of binary bit

• Digital instrument draws only

negligible power

• Cost is high and not easily

portable

Page 22: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Types Of Numbers

• Natural Numbers

– The number 0 and any number obtained by

repeatedly adding a count of 1 to 0

• Negative Numbers

– A value less than 0

• Integer

– A natural number, the negative of a natural number,

and 0.

– So an integer number system is a system for

‘counting’ things in a simple systematic way

Page 23: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Exponent Review

• An exponent (power) tells you how many times to

multiply the base by itself:

– 21 = 2

– 22 = 2 x 2 =4

– 23 = 2 x 2 x 2 = 8

• 20 = 1 (ANY number raised to power 0 is 1)

• 1 / x2 = x -2

Page 24: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal Numbering System

• How is a positive integer represented in decimal?

• Let’s analyze the decimal number 375:

375 = (3 x 100) + (7 x 10) + (5 x 1)

= (3 x 102) + (7 x 101) + (5 x 100)

5 x100 = 5 +

7 x101 = 70 +

3 x 102 = 300

375

5 7 3

102 101 100 Position weights

Number digits

Page 25: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal System Principles

• A decimal number is a sequence of digits

• Decimal digits must be in the set:

{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} (Base 10)

• Each digit contributes to the value the number

represents

• The value contributed by a digit equals the product of

the digit times the weight of the position of the digit in

the number

Page 26: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal System Principles

• Position weights are powers of 10

• The weight of the rightmost (least significant digit)

is 100 (i.e.1)

• The weight of any position is 10x, where x is the

number of positions to the right of the least

significant digit

Position weights digits

104 103 102 101 100

3 7 5

Page 27: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Bits

• In a computer, information is stored using digital

signals that translate to binary numbers

• A single binary digit (0 or 1) is called a bit

– A single bit can represent two possible states,

on (1) or off (0)

• Combinations of bits are used to store values

Page 28: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Data Representation

• Data representation means encoding data into bits

– Typically, multiple bits are used to represent the

‘code’ of each value being represented

• Values being represented may be characters, numbers,

images, audio signals, and video signals.

• Although a different scheme is used to encode each type

of data, in the end the code is always a string of zeros

and ones

Page 29: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Binary

24 23 22 21 20 Position weights

digits

• So in a computer, the only possible digits we can use to

encode data are {0,1}

– The numbering system that uses this set of digits is

the base 2 system (also called the Binary Numbering

System)

• We can apply all the principles of the base 10 system to

the base 2 system

1 0 1 1

Page 30: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary Numbering System

• How is a positive integer represented in binary?

• Let’s analyze the binary number 110:

110 = (1 x 22) + (1 x 21) + (0 x 20)

= (1 x 4) + (1 x 2) + (0 x 1)

So a count of SIX is represented in binary as 110

0 +

2 +

4

6

0 x20 =

1 x21 =

1 x 22 =

20

0

22 21

1 1

Position weights

Number digits

Page 31: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Decimal Conversion

To convert a base 2 (binary) number to base

10 (decimal):

Add all the values (positional weights)

where a one digit occurs

Positions where a zero digit occurs do

NOT add to the value, and can be

ignored

Page 32: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Decimal Conversion

Example: Convert binary 100101 to decimal

(written 1 0 0 1 0 12 ) =

1*20 +

0*21 +

1*22 +

0*23 +

0*24 +

1*25

1 +

4 +

32

3710

Page 33: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Decimal Conversion

Example #2: 101112

positional powers of 2: 24 23 22 21 20

decimal positional value: 16 8 4 2 1

binary number: 1 0 1 1 1

16 + 4 + 2 + 1 = 2310

Page 34: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Decimal Conversion

Example #3: 1100102

positional powers of 2: 25 24 23 22 21 20

decimal positional value: 32 16 8 4 2 1

binary number: 1 1 0 0 1 0

32 + 16 + 2 = 5010

Page 35: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Binary Conversion

The Division Method:

1) Start with your number (call it N) in base 10

2) Divide N by 2 and record the remainder

3) If (quotient = 0) then stop

else make the quotient your new N, and go back to step 2

The remainders comprise your answer, starting with the last

remainder as your first (leftmost) digit.

In other words, divide the decimal number by 2 until you reach

zero, and then collect the remainders in reverse.

Page 36: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Binary Conversion

Using the Division Method: Divide decimal number by 2 until you reach zero, and then

collect the remainders in reverse.

E 101102

xample 1: 2210 =

2 ) 22 Rem:

2 ) 11 0

2 ) 5 1

2 ) 2 1

2 ) 1 0

0 1

Page 37: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Binary Conversion

Using the Division Method

E

1110002

xample 2: 5610 =

2 ) 56 Rem:

2 ) 28 0

2 ) 14 0

2 ) 7 0

2 ) 3 1

2 ) 1 1

0 1

Page 38: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Binary Conversion

The Subtraction Method:

Subtract out largest power of 2 possible (without going below zero), repeating until you reach 0.

Place a 1 in each position where you COULD subtract the value

Place a 0 in each position that you could NOT subtract out the value without going below zero.

Page 39: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Binary Conversion

Example 1: 2110

21

- 16

5 1 0 1 0 1 - 4

1

- 1 Answer: 2110 = 101012

0

26 25 24 23 22 21 20

64 32 16 8 4 2 1

Page 40: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Binary Conversion

Example 2: 5610

56 26 | 25 24 23 22 21 20

- 32 64| 32 16 8 4 2 1

24 | 1 1 1 0 0 0

- 16

8

- 8 Answer: 5610 = 1110002

0

Page 41: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Octal Numbering System

• Base: 8 • Digits: 0, 1, 2, 3, 4, 5, 6, 7

Octal number: 3578

= (3 x 82 ) + (5 x 81) + (7 x 80)

To convert to base 10, beginning with the

rightmost digit, multiply each nth digit by 8(n-1), and add all of the results together.

Page 42: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Octal to Decimal Conversion

Example 1: 3578

positional powers of 8: 82 81 80

decimal positional value: 64 8 1

Octal number: 3 5 7

(3 x 64) + (5 x 8) + (7 x 1)

= 192 + 40 + 7 = 23910

Page 43: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Octal to Decimal Conversion

• Example 2: 12468

positional powers of 8: 83 82 81 80

decimal positional value: 512 64 8 1

Octal number: 1 2 4 6

(1 x 512) + (2 x 64) + (4 x 8) + (6 x 1)

= 512 + 128 + 32 + 6 = 67810

Page 44: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Octal Conversion

The Division Method:

1) Start with your number (call it N) in base 10

2) Divide N by 8 and record the remainder

3) If (quotient = 0) then stop

else make the quotient your new N, and go back to step 2

The remainders comprise your answer, starting with the last

remainder as your first (leftmost) digit.

In other words, divide the decimal number by 8 until you reach

zero, and then collect the remainders in reverse.

Page 45: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Octal Conversion

Using the Division Method:

Example 1: 21410 = 3268

8 ) 214 Rem:

8 ) 26 6

8 ) 3 2

0 3

Page 46: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Octal Conversion

Example 2: 433010 = 103528

8 ) 4330 Rem:

8 ) 541 2

8 ) 67 5

8 ) 8 3

8 ) 1 0

0 1

Page 47: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Octal Conversion

The Subtraction Method:

Subtract out multiples of the largest power of 8 possible (without going below zero) each time until you reach 0.

Place the multiple value in each position where you COULD subtract the value.

Place a 0 in each position that you could NOT subtract out the value without going below zero.

Page 48: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Octal Conversion

Example 1: 31510

315

- 256 (4 x 64)

59

- 56 (7 x 8)

3

82 81 80

64 8 1

4 7 3

- 3 (3 x 1)

0 Answer: 31510 = 4738

Page 49: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Octal Conversion

Example 2: 201810

2018 84 83 82 81 80

-1536 (3 x 512) 4096 512 64 8 1

482 3 7 4 2

- 448 (7 x 64)

34

- 32 (4 x 8)

2

- 2 (2 x 1) Answer: 201810 = 37428

0

Page 50: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Hexadecimal (Hex) Numbering System

• Base: 16 • Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Hexadecimal number: 1F416

= (1 x 162 ) + (F x 161) + (4 x 160)

Page 51: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Hexadecimal (Hex) Extra Digits

Decimal Value Hexadecimal Digit

10 A

11 B

12 C

13 D

14 E

15 F

Page 52: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Hex to Decimal Conversion

• To convert to base 10:

– Begin with the rightmost digit

– Multiply each nth digit by 16(n-1)

– Add all of the results together

Page 53: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Hex to Decimal Conversion

• Example 1: 1F416

positional powers of 16: 163 162 161 160

decimal positional value: 4096 256 16 1

Hexadecimal number: 1 F 4

(1 x 256) + (F x 16) + (4 x 1)

= (1 x 256) + (15 x 16) + (4 x 1)

= 256 + 240 + 4 = 50010

Page 54: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Hex to Decimal Conversion

• Example 2: 25AC16

positional powers of 16: 163 162 161 160

decimal positional value: 4096 256 16 1

Hexadecimal number: 2 5 A C

(2 x 4096) + (5 x 256) + (A x 16) + (C x 1)

= (2 x 4096) + (5 x 256) + (10 x 16) + (12 x 1)

= 8192 + 1280 + 160 + 12 = 964410

Page 55: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Hex Conversion

The Division Method:

1) Start with your number (call it N) in base 10

2) Divide N by 16 and record the remainder

3) If (quotient = 0) then stop

else make the quotient your new N, and go back to step 2

The remainders comprise your answer, starting with the last

remainder as your first (leftmost) digit.

In other words, divide the decimal number by 16 until you

reach zero, and then collect the remainders in reverse.

Page 56: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Hex Conversion

Using The Division Method:

Example 1: 12610 =

16) 126 Rem:

16) 7 14=E

0 7

7E16

Page 57: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Hex Conversion

Example 2: 60310 =

16) 603 Rem:

16) 37 11=B

16) 2 5

0 2

25B16

Page 58: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Hex Conversion

The Subtraction Method:

Subtract out multiples of the largest power of 16 possible (without going below zero) each time until you reach 0.

Place the multiple value in each position where you COULD to subtract the value.

Place a 0 in each position that you could NOT subtract out the value without going below zero.

Page 59: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Hex Conversion

Example 1: 81010

810 162 161 160

- 768 (3 x 256) 256 16 1

42

- 32 (2 x 16)

10

3 2 A

- 10 (10 x 1)

0 Answer: 81010 = 32A16

Page 60: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Decimal to Hex Conversion

Example 2: 15610

156

- 144 (9 x 16)

12

- 12 (12 x 1)

0

162 161 160

256 16 1

9 C

Answer: 15610 = 9C16

Page 61: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Octal Conversion

The maximum value represented in 3 bit is: 23 – 1 = 7

So using 3 bits we can represent values from

0 to 7 which are the digits of the Octal numbering system.

Thus, three binary digits can be converted to one

octal digit.

Page 62: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Octal Conversion

Three-bit Group Decimal Digit Octal Digit

000 0 0

001 1 1

010 2 2

011 3 3

100 4 4

101 5 5

110 6 6 111 7 7

Page 63: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Octal to Binary Conversion

Ex : Convert 7428 to binary

Convert each octal digit to 3 bits:

7 = 111

4 = 100

2 = 010

111 100 010

7428 = 1111000102

Page 64: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Octal Conversion

Ex : Convert 101001102 to octal

Starting at the right end, split into groups of 3:

10 100 110

110 = 6

100 = 4

010 = 2 (pad empty digits with 0)

101001102 = 2468

Page 65: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Hex Conversion

The maximum value represented in 4 bit is: 24 – 1 = 15

So using 4 bits we can represent values from

0 to 15 which are the digits of the Hexadecimal numbering system.

Thus, four binary digits can be converted to one

hexadecimal digit.

Page 66: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Hex Conversion

Four-bit Group Decimal Digit Hexadecimal Digit 0000 0 0

0001 1 1

0010 2 2

0011 3 3

0100 4 4

0101 5 5

0110 6 6

0111 7 7

1000 8 8

1001 9 9

1010 10 A

1011 11 B

1100 12 C

1101 13 D

1110 14 E

1111 15 F

Page 67: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary to Hex Conversion

Ex : Convert 1101001102 to hex

Starting at the right end, split into groups of 4:

(pad empty digits with 0)

1101001102 = 1A616

1 1010 0110 0110 = 6 1010 = A 0001 = 1

Page 68: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Hex to Binary Conversion

Ex : Convert 3D916 to binary

Convert each hex digit to 4 bits:

3 = 0011

D = 1101

9 = 1001

0011 1101 1001

3D916 = 11110110012 (can remove leading zeros)

Page 69: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Conversion between Binary and Hex - Try It Yourself

• Convert the following numbers:

–10101111012 to Hex

–82F16 to Binary

• (Answers on NEXT slide)

Page 70: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Answers

• 10101111012 10 1011 1101

= 2BD16

• 82F16 = 0100 0010 1111

100001011112

Page 71: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Octal to Hex Conversion

To convert between the Octal and Hexadecimal numbering systems

Convert from one system to binary first

Then convert from binary to the new numbering system

Page 72: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Hex to Octal Conversion

First convert the hex to binary:

Ex : Convert E8A16 to octal

1110 1000 10102

111 010 001 010 and re-group by 3 bits

(starting on the right)

Then convert the binary to octal: 7 2 1 2

So E8A16 = 72128

Page 73: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Octal to Hex Conversion

Ex : Convert 7528 to hex

First convert the octal to binary:

111 101 0102

re-group by 4 bits

0001 1110 1010 (add leading zeros)

Then convert the binary to hex: 1 E A

So 7528 = 1EA16

Page 74: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Basic Logic Gates and Basic Digital Design

• NOT, AND, and OR Gates

• NAND and NOR Gates

• DeMorgan’s Theorem

• Exclusive-OR (XOR) Gate

• Multiple-input Gates

Page 75: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

NOT Gate -- Inverter

NOT

Y = ~X

X Y

X

0

1

Y

1

0

Page 76: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

NOT

• Y = ~X (Verilog)

• Y = !X (ABEL)

• Y = not X (VHDL)

• Y = X’

• Y = X

• Y = X (textook)

• not(Y,X) (Verilog)

Page 77: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

NOT

X ~X ~~X = X

X ~X ~~X

0 1 0

1 0 1

Page 78: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

AND Gate

AND

X

Z

Y

Z = X & Y

X

0

0

1

1

Y

0

1

0

1

Z

0

0

0

1

Page 79: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

AND

• X & Y (Verilog and ABEL)

• X and Y (VHDL)

• X Y

• X Y

• X * Y

• XY (textbook)

• and(Z,X,Y) (Verilog)

Page 80: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

OR Gate

OR

X

Z

Y

Z = X | Y

X Y Z

0 0 0

0 1 1

1 0 1

1 1 1

Page 81: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

OR

• X | Y (Verilog)

• X # Y (ABEL)

• X or Y (VHDL)

• X + Y (textbook)

• X V Y

• X U Y

• or(Z,X,Y) (Verilog)

Page 82: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Basic Logic Gates and Basic Digital Design

• NOT, AND, and OR Gates

• NAND and NOR Gates

• DeMorgan’s Theorem

• Exclusive-OR (XOR) Gate

• Multiple-input Gates

Page 83: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

NAND Gate

NAND

X

Z

Y

Z = ~(X & Y)

nand(Z,X,Y)

X

0

0

1

1

Y

0

1

0

1

Z

1

1

1

0

Page 84: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

NAND Gate

NOT-AND

X

Y

Z

1 0 0 1

1 1 1 0

W = X & Y

Z = ~W = ~(X & Y)

W

X Y W Z

0 0 0 1

0 1 0 1

Page 85: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

NOR Gate

NOR

X

Z

Y

Z = ~(X | Y)

nor(Z,X,Y)

X Y Z

0 0 1

0 1 0

1 0 0

1 1 0

Page 86: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

NOR Gate

NOT-OR

X W

Z

Y

W = X | Y

Z = ~W = ~(X | Y)

X Y W Z

0 0 0 1

0 1 1 0

1 0 1 0

1 1 1 0

Page 87: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Basic Logic Gates and Basic Digital Design

• NOT, AND, and OR Gates

• NAND and NOR Gates

• DeMorgan’s Theorem

• Exclusive-OR (XOR) Gate

• Multiple-input Gates

Page 88: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

NAND Gate

X Z =

X Z

Y Y

Z = ~(X & Y) Z = ~X | ~Y

X Y W Z X Y ~X ~Y Z

0 0 0 1 0 0 1 1 1

0 1 0 1 0 1 1 0 1

1 0 0 1 1 0 0 1 1

1 1 1 0 1 1 0 0 0

Page 89: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

De Morgan’s Theorem-1

~(X & Y) = ~X | ~Y

• NOT all variables

• Change & to | and | to &

• NOT the result

Page 90: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

NOR Gate

X X Z Z

Y Y

Z = ~(X | Y) Z = ~X & ~Y

X Y Z X Y ~X ~Y Z

0 0 1 0 0 1 1 1

0 1 0 0 1 1 0 0

1 0 0 1 0 0 1 0

1 1 0 1 1 0 0 0

Page 91: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

De Morgan’s Theorem-2

~(X | Y) = ~X & ~Y

• NOT all variables

• Change & to | and | to &

• NOT the result

Page 92: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

De Morgan’s Theorem

• NOT all variables

• Change & to | and | to &

• NOT the result

• --------------------------------------------

• ~X | ~Y = ~(~~X & ~~Y) = ~(X & Y)

• ~(X & Y) = ~~(~X | ~Y) = ~X | ~Y

• ~X & !Y = ~(~~X | ~~Y) = ~(X | Y)

• ~(X | Y) = ~~(~X & ~Y) = ~X & ~Y

Page 93: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Basic Logic Gates and Basic Digital Design

• NOT, AND, and OR Gates

• NAND and NOR Gates

• DeMorgan’s Theorem

• Exclusive-OR (XOR) Gate

• Multiple-input Gates

Page 94: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Exclusive-OR Gate

XOR

X

Y Z

Z = X ^ Y

xor(Z,X,Y)

X Y Z

0 0 0

0 1 1

1 0 1

1 1 0

Page 95: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

XOR

• X

• X

• X

^

$

@

Y

Y

Y

(Verilog)

(ABEL)

X Y (textbook)

• xor(Z,X,Y) (Verilog)

Page 96: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Exclusive-NOR Gate

XNOR

X

Y Z

Z = ~(X ^ Y)

Z = X ~^ Y

xnor(Z,X,Y)

X Y Z

0 0 1

0 1 0

1 0 0

1 1 1

Page 97: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

XNOR

• X ~^ Y (Verilog)

• !(X $ Y) (ABEL)

• X @ Y

X Y

• xnor(Z,X,Y) (Verilog)

Page 98: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Basic Logic Gates and Basic Digital Design

• NOT, AND, and OR Gates

• NAND and NOR Gates

• DeMorgan’s Theorem

• Exclusive-OR (XOR) Gate

• Multiple-input Gates

Page 99: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Multiple-input Gates

Z 1 Z 2

Z 3 Z 4

Page 100: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Multiple-input AND Gate

Z 1

Output Z 1 is HIGH only if all inputs are HIGH

An open input will float HIGH

Page 101: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Multiple-input OR Gate

Z 2

Output Z 2 is LOW only if all inputs are LOW

Page 102: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Multiple-input NAND Gate

Z 3

Output Z 3 is LOW only if all inputs are HIGH

Page 103: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Multiple-input NOR Gate

Z 4

Output Z 4 is HIGH only if all inputs are LOW

Page 104: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binarycodes:- BCD, GRAY,EBCDIC, ASCII

• It is the symbolic representation of discrete information which

may be represented in the form of numeric, alphabets &

special characters.

• In Digital Electronics, the binary digits 0 & 1 are used to

represent these symbols & are arranged according to the

rules of specific code.

• Infect, a binary code is a group of n-bits that can represent

distinct symbols.

• The interpretation of thebinary information is possible only if

the code in which this information is available is known.

Page 105: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary codes:- BCD, GRAY,EBCDIC, ASCII

(A) Straight Binary Code

Used to represent numbers using natural (or straight) binary form.

1. Natural BCD Code In this code, decimal 0 through 9 are represented by their natural binary

equivalents using four bits and eachdecimal digit is represented bythis four bit

codeindividually. Thiscodeisalsoknownas 8-4-2-1 codewhere 8, 4, 2,& 1 are

the weights of the four bits of the binary code of each decimal digit to the

straight binary system.

2. EXCESS-3 Codes This is another form of BCDcode, inwhich each decimal is coded into a 4-bit binary code.

Thecodefor eachdecimaldigit isobtained byaddingdecimal 3tothenatural BCDcodeof

the digit. For ex- decimal 2 is coded as 0010+0011=0101 in Excess-3 code.

Page 106: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary codes:- BCD, GRAY, EBCDIC, ASCII

3. Gray Code

It is a very useful code in which a decimal number is represented in binary form in such a

way so that each gray code number differs from preceding & the succeeding number by a

single bit. For ex- the gray code for decimal number 5 is 0111 & for 6 is 0101. These two

codes differ by only one bit position (third from left). This code is used extensively for the

shaft encoders because of this property. These can be constructed by using the property

given below:-

• A 1-bit Gray code has two code words 0 & 1 representing decimal numbers 0 & 1.

• An n-bit (n≥2) Gray code will have first with the leading 0 appended.

• The last Graycodes with the leading 1 appended, will be equal to the Graycode

words of an (n-1)-bit Gray code, written in reverse order (assuming a mirror placed between first & last Graycodes) with a leading 1 appended.

Page 107: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Classification ofCodes 1. Weighted & Non-weighted Codes

2. Self Complimentary & Sequential Codes

3. Alphanumeric codes

4. Error detection & Error correction Codes

1. Weighted Codes

The main characteristic of weighted code is that each binary digit is assigned a

specific weight. The common example of weighted code is BCD code or 8421

code in which the weights of different bits are 1, 2, 4 & 8.

Non-Weighted Code

These don’t follow the principle of positional weighting system i.e. each position

within the number doesn’t follow or have any fixed weight. For ex- Excess-3, Gray

code.

Page 108: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

2. Sequential Code

These are those codes in which each succeeding code is 1 binary

number greater than the preceding code. This property is used for

mathematical manipulation of data. For ex:- BCD

And Excess-3 Code.

3. Self-complementary Code

• A code is said to be self-complementary if the code for 9’s

complement of N i.e. 9-Ncanbeobtained by interchanging all 0s

and 1s.

• Decimal 9 is the complement of code for 0, 8 for 1, 7 for 2 and so on.

• For a code to be self complementing, the sum of all its weights

must be 9. digit.8421 and 5421 codes are not self complementing

codes whereas 5211,2421,3321, 4321 are self complementing.

• In general, a code is self-complementary if we produce a code by

taking the first complement of the digit which is same as 9’s

complement of the number.

Page 109: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

• Cyclic codes: Cyclic codes are those in which each successive

code word differs from the preceding one in only one bit

position.

• They are also called unit distance codes

• Example: gray code

Reflective Code:

Example : Graycode.

Page 110: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Alphanumeric Codes • Apartfromnumericdata, acomputersystemmayprocess

somealphanumericdatajustliketheemployees’ names,

address as well as some special characters. An Alphanumeric

datagenerallyconsistofsequenceofcharacterswherea

character is any one of the following:-

• Letters or alphabets

• Digits 0-9

• Special characters(+,-,π)

• In thecomputersystem, eachcharacterisstoredinsome

code form depending upon the coding scheme. The

charactermaytake6, 7, or8 bits.Therearenumberofcodes

which are used for some specific application i.e. ASCII Code,

EBCDIC Code, UNIT Code, etc.

Page 111: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

VARIOUS DECIMAL CODES

Page 112: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Importance ofCodes

1. The code refers to encryption system.

2.Computer and other digital circuits process data in

binary format.

3. Various binary codes are used to represent data.

4. The interpretation of data is only possible if the

code in which the information is available is known.

Page 113: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary Coded Decimal (BCD)

• Wouldit be easyfor youifyoucan replace a decimal number with an individual binary code?

– Such as 0001 1001 = 1910

• The 8421 code is a type of BCD to do that.

• BCD code provides an excellent interface to binary systems:

– Keypad inputs

– Digital readouts

11

Page 114: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary Coded Decimal (BCD)

– Used to represent the decimal digits 0 - 9.

– 4 bits areused.

– Eachbit positionhasaweight associated with it (weightedcode).

– Weights are: 8, 4, 2, and 1 from MSB to LSB (called 8-4-2-1 code).

– BCD Codes:

0: 0000 4: 0100 8: 1000

1: 0001 5: 0101 9: 1001

2: 0010 6: 0110

3: 0011 7: 0111

– Used to encode numbers for output to numerical displays

– Used in processors that perform decimal arithmetic.

– Example: (9750)10 = (1001 0111 0101 0000)BCD

9 7 5 0

12

Page 115: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Binary CodedDecimal

Decimal

Digit 0 1 2 3 4 5 6 7 8 9

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE !

ex1: Decimal to BCD

(a) 35

(b) 98

(c) 170

(d) 2469

ex2: BCD-to-Decimal

(a) 10000110

(b) 001101010001

(c) 1001010001110000

13

Page 116: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

BCD Addition • BCD is a numerical code and can be used in

arithmetic operations. Here is how to add two BCD

numbers:

– Addthe two BCD numbers, using the rules for basic binary

addition.

– Ifa 4-bit sum is equalto or less than 9, it is avalid BCD

number.

– If a 4-bit sum > 9, or if a carry out of the 4 -bit group is

generatedit isaninvalidresult.Add6(0110)toa4-bitsum

in order to skip the sixinvalid states and return the code to

8421. If a carry results when 6 is added, simply add the

carry to the next 4 -bit group.

14

Page 117: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

BCD Subtraction

• Here is how to subtract two BCD numbers:

– Subtract the two BCD numbers, usingthe rulesfor basic

binary subtraction.

– If there is no borrowfrom the nexthigher group, no

correction is required.

– If there isborrowfromthe nextgroup,then (0110)is

subtracted from the difference term of this group.

– Example 38 –15

38 0011 1000 (38 in BCD)

15 0001 0101 (15 in BCD)

– 0010 0011 (No borrow, so it is a correct answer) 16

Page 118: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

The Gray Code

• The Gray code is unweighted and is not an

arithmetic code.

– There are no specific weights assigned to the bit

positions. 18

Page 119: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

The Gray Code

• Binary-to-Gray code conversion

– The MSB in the Graycode is the same as

corresponding MSB in the binary number.

– Going from left to right, add each adjacent pair of

binary code bits to get the next Gray code bit.

Discard carries.

ex: convert 101102 to Gray code

1 + 0 + 1 + 1 + 0 binary

1

1

1

0

1 Gray

19

Page 120: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

The Gray Code

• Gray-to-Binary Conversion

– The MSB in the binary code is the same as the

corresponding bit in the Gray code.

– Add each binary code bit generated to the Gray code bit in

the next adjacent position. Discard carries.

ex: convert the Gray code word 11011 to binary

Gray Binary

1 1 0 1 1

+ + + +

1 0 0 1 0

20

Page 121: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

The Gray Code

21

Decimal Binary Gray Code

8 1000 1100

9 1001 1101

10 1010 1111

11 1011 1110

12 1100 1010

13 1101 1011

14 1110 1001

15 1111 1000

Decima l

Binary Gray Code

0 0000 0000

1 0001 0001

2 0010 0011

3 0011 0010

4 0100 0110

5 0101 0111

6 0110 0101

7 0111 0100

Page 122: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Excess 3 Code

• A BCD Code formed by adding 3 (0011)

to its true four bit binary value.

• Excess 3 is a self complementing code. If

the bits of the Excess-3 digit are inverted,

they yield the 9’s complement of the

decimal equivalent.

• Excess-3 code is useful for performing

decimal arithmetic digitally.

Page 123: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Excess 3

Examples

• 3 = 0011 + 0011 = 0110 = 6 in E-3.

• 1 = 0001 + 0011 = 0100 = 4 in E-3

• If we complement 1’s = 1011 in E-3 this

is the code for an 8.

• 9s Complement of 1(0100) = (9 - 1) = 8

Self Complement

Page 124: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

Alphanumeric Codes

• Represent numbers and alphabetic characters.

– Also represent othercharacters such as symbols and various instructions necessary for conveying

information.

• TheASCIIisthe most common alphanumeric

code.

– ASCII = American Standard Code for Information

Interchange

Page 125: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing

ASCII

• ASCII has 128 characters and symbols

represented bya 7-bit binary code.

– It can be considered an 8-bit code with the MSB

always 0. (00h-7Fh)

• 00h-1Fh (the first 32) – control characters

• 20h-7Fh – graphics symbols (can be printed or

displayed)

25

Page 126: Boolean Algebra · • 1854: Logical algebra was published by George Boole known today as “Boolean Algebra” – It’s a convenient way and systematic way of expressing and analyzing