54
Binary Number System & Logic Operations

Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Embed Size (px)

Citation preview

Page 1: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Binary Number System &

Logic Operations

Page 2: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

The focus of the last lecture was on the microprocessor

• During that lecture we learnt about the function of the central component of a computer, the microprocessor

• And its various sub-systems– Bus interface unit– Data & instruction cache memory– Instruction decoder– ALU– Control unit

Page 3: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Learning Goals for Today

1. To become familiar with number system used by the microprocessors - binary numbers

2. To become able to perform decimal-to-binary conversions

3. To understand the NOT, AND, OR and XOR logic operations – the fundamental operations that are available in all microprocessors

Page 4: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

BINARY(BASE 2)

numbers

Page 5: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

DECIMAL(BASE 10)

numbers

Page 6: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Decimal (base 10) number system consists of 10 symbols or digits

0 1 2 3 4

5 6 7 8 9

Page 7: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Decimal

The numbers are represented in Units, Tens, Hundreds, Thousands; in other words as 10power.

191=1 x 102 + 9 x 101 + 1 x 100

increasing power

Th.Hund.Tens.Units

Page 8: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Binary (base 2) number system consists of just two

0 1

Page 9: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Binary

On the pattern of Decimal numbers one could visualize Binary Representations:

Powers

1012=1 x 22 +0 x 21 + 1 x 20 =510

Page 10: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Conversion

2 240

2 120 0

2 60 0

2 30 0

2 15 0

2 7 1

2 3 1

2 1 1

= 11110000128 64 32 16 8 4 2 1

= 128 + 64 + 32 + 16 = 240

Decimal to Binary

Binary to Decimal

Page 11: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Other popular number systems

• Octal– base = 8– 8 symbols (0,1,2,3,4,5,6,7)

• Hexadecimal– base = 16– 16 symbols (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)

Page 12: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Codes

• Octal Power

• Hexadecimal

83 82 81 80

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 1 2 3 4 5 6 7 8 9 A B C D E F

Page 13: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Code conversions

Decimal to Octal

Similar to Dec-to Binary:

Start dividing by 8

and build Octal figures from Remainders:

24010=3608

8 240

8 30 0

8 3 6

0 3

Page 14: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Code conversionsBinary –to-Octal

3 bits of binary could provide weight of 810, that is equivalent to Octal;i.e:

Bits: b2 b1 b0

Wts: 4 2 1

Bin: 1 1 1 710 and Octal range 0-7

Example: 100111010= 100 111 010

Octal Values: 4 7 2

Page 15: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Octal Conversionbinary: Octal:

011 010 1102

3 2 6 3268

256 128 64 32 16 8 4 2 1

3 x 82 + 2 x 81 + 6 x 80

Page 16: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Decimal (base 10) numbers are expressed in the positional notation

4202 = 2x100 + 0x101 + 2x102 + 4x103

The right-most is the least significant digit

The left-most is the most significant digit

Page 17: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Decimal (base 10) numbers are expressed in the positional notation

4202 = 2x100 + 0x101 + 2x102 + 4x103

1’s multiplier

1

Page 18: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Decimal (base 10) numbers are expressed in the positional notation

4202 = 2x100 + 0x101 + 2x102 + 4x103

10’s multiplier

10

Page 19: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Decimal (base 10) numbers are expressed in the positional notation

4202 = 2x100 + 0x101 + 2x102 + 4x103

100’s multiplier

100

Page 20: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Decimal (base 10) numbers are expressed in the positional notation

4202 = 2x100 + 0x101 + 2x102 + 4x103

1000’s multiplier

1000

Page 21: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Binary (base 2) numbers are also expressed in the positional notation

10011 = 1x20 + 1x21

+ 0x22 + 0x23

+ 1x24

The right-most is the least significant digit

The left-most is the most significant digit

Page 22: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Binary (base 2) numbers are also expressed in the positional notation

10011 = 1x20 + 1x21

+ 0x22 + 0x23

+ 1x24

1’s multiplier

1

Page 23: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Binary (base 2) numbers are also expressed in the positional notation

10011 = 1x20 + 1x21

+ 0x22 + 0x23

+ 1x24

2’s multiplier

2

Page 24: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Binary (base 2) numbers are also expressed in the positional notation

10011 = 1x20 + 1x21

+ 0x22 + 0x23

+ 1x24

4’s multiplier

4

Page 25: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Binary (base 2) numbers are also expressed in the positional notation

10011 = 1x20 + 1x21

+ 0x22 + 0x23

+ 1x24

8’s multiplier

8

Page 26: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Binary (base 2) numbers are also expressed in the positional notation

10011 = 1x20 + 1x21

+ 0x22 + 0x23

+ 1x24

16’s multiplier

16

Page 27: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Counting in Decimal0123456789

10111213141516171819

20212223242526272829

30313233343536...

01

1011

100101110111

10001001

101010111100110111101111

10000100011001010011

10100101011011010111110001100111010110111110011101

1111011111

100000100001100010100011100100

.

.

.

Counting in Binary

Page 28: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Why binary?Because this system is natural for digital computers

The fundamental building block of a digital computer – the switch – possesses two natural states, ON & OFF.

It is natural to represent those states in a number system that has only two symbols, 1 and 0, i.e. the binary number system

In some ways, the decimal number system is natural to us humans. Why?

Page 29: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

bitbinary diginary digit

Page 30: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Byte = 8 bits

Page 31: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Decimal Binary conversion

Page 32: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Convert 75 to Binary75237 1218 129 024 122 021 020 1

1001011

remainder

Page 33: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Check

1001011 = 1x20 + 1x21

+ 0x22 + 1x23

+

0x24 + 0x25

+ 1x26

= 1 + 2 + 0 + 8 + 0 + 0 + 64

= 75

Page 34: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Convert 100 to Binary100250 0225 0212 126 023 021 120 1

1100100

remainder

Page 35: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

That finishes our first topic - introduction to binary numbers and their conversion to and from decimal numbers

Our next topic is …

Page 36: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Boolean Logic

Operations

Page 37: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Let x, y, z be Boolean

variables. Boolean variables can only have binary values i.e., they can have values which are either 0 or 1

For example, if we represent the state of a light switch with a Boolean variable x, we will assign a value of 0 to x when the switch is OFF, and 1 when it is ON

Page 38: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

A few other names for the states of these Boolean variables

0 1

Off On

Low High

False True

Page 39: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

We define the following logic operations or functions among the Boolean variables

Name Example Symbolically

NOT y = NOT(x) x´

AND z = x AND y x · y

OR z = x OR y x + y

XOR z = x XOR y x y

Page 40: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

We’ll define these operations with the help of truth tables

what is the truth table of a logic function

A truth table defines the output of a logic function for all possible inputs

?

Page 41: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Truth Table for the NOT Operation(y true whenever x is false)

x y = x´0

1

Page 42: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Truth Table for the NOT Operation

x y = x´0 1

1 0

Page 43: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Truth Table for the AND Operation(z true when both x & y true)

x y z = x · y0 0

0 1

1 0

1 1

Page 44: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Truth Table for the AND Operation

x y z = x · y0 0 0

0 1 0

1 0 0

1 1 1

Page 45: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Truth Table for the OR Operation(z true when x or y or both true)

x y z = x + y0 0

0 1

1 0

1 1

Page 46: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Truth Table for the OR Operation

x y z = x + y0 0 0

0 1 1

1 0 1

1 1 1

Page 47: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Truth Table for the XOR Operation(z true when x or y true, but not both)

x y z = x y0 0

0 1

1 0

1 1

Page 48: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Truth Table for the XOR Operation

x y z = x y0 0 0

0 1 1

1 0 1

1 1 0

Page 49: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Those 4 were the fundamental logic operations. Here are examples of a few more complex situations

z = (x + y)´

z = y · (x + y)

z = (y · x) w

STRATEGY: Divide & Conquer

Page 50: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

x y x + y z = (x + y)´0 0 0 1

0 1 1 0

1 0 1 0

1 1 1 0

z = (x + y)´

Page 51: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

x y x + y z = y · (x + y)

0 0 0 0

0 1 1 1

1 0 1 0

1 1 1 1

z = y · (x + y)

Page 52: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

x y w y · x z = (y · x) w

0 0 0 0 0

0 0 1 0 1

0 1 0 0 0

0 1 1 0 1

1 0 0 0 0

1 0 1 0 1

1 1 0 1 1

1 1 1 1 0

z = (y · x) w

Page 53: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

Number of rows in a truth table?

2n

n = number of input variables

Page 54: Binary Number System & Logic Operations. The focus of the last lecture was on the microprocessor During that lecture we learnt about the function of the

What have we learnt today?

1. About the binary number system, and how it differs from the decimal system

2. Positional notation for representing binary and decimal numbers

3. A process (or algorithm) which can be used to convert decimal numbers to binary numbers

4. Basic logic operations for Boolean variables, i.e. NOT, OR, AND, XOR, NOR, NAND, XNOR

5. Construction of truth tables (How many rows?)