# binary numbers logic operations

Post on 07-Apr-2018

221 views

Category:

## Documents

Embed Size (px)

TRANSCRIPT

• 8/6/2019 Binary Numbers Logic Operations

1/49

CS101 Introduction to Computing

Lecture 8Binary Numbers & Logic Operations

• 8/6/2019 Binary Numbers Logic Operations

2/49

The focus of the last lecture was

on th

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

microprocessor

And its various sub-systems

Bus interface unit

Data & instruction cache memory

Instruction decoder

ALU

Floating-point unit

Control unit

• 8/6/2019 Binary Numbers Logic Operations

3/49

Learning Goals forToday

1. To become familiar with number system used by

the microprocessors - binary numbers

2. To become able to perform decimal-to-binaryconversions

3. To understand the NOT, AND, OR and XOR logic

operations the fundamental operations that are

available in all microprocessors

• 8/6/2019 Binary Numbers Logic Operations

4/49

BINARY(BASE 2)

numbers

• 8/6/2019 Binary Numbers Logic Operations

5/49

DECIMAL(BASE 10)

numbers

• 8/6/2019 Binary Numbers Logic Operations

6/49

Decimal (base 10) number system

consists of 10 symbols or digits

0 1 2 3 4

5 6 7 8 9

• 8/6/2019 Binary Numbers Logic Operations

7/49

Binary (base 2) number system

consists of just two

• 8/6/2019 Binary Numbers Logic Operations

8/49

Other popular number systems

Octal

base = 8

8 symbols (0,1,2,3,4,5,6,7)

base = 16

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

• 8/6/2019 Binary Numbers Logic Operations

9/49

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

• 8/6/2019 Binary Numbers Logic Operations

10/49

Decimal (base 10) numbers are

expressed in thepositional notation

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

1s multiplier

1

• 8/6/2019 Binary Numbers Logic Operations

11/49

Decimal (base 10) numbers are

expressed in thepositional notation

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

10s multiplier

10

• 8/6/2019 Binary Numbers Logic Operations

12/49

Decimal (base 10) numbers are

expressed in thepositional notation

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

100s multiplier

100

• 8/6/2019 Binary Numbers Logic Operations

13/49

Decimal (base 10) numbers are

expressed in thepositional notation

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

1000s multiplier

1000

• 8/6/2019 Binary Numbers Logic Operations

14/49

Binary (base 2) numbers are also

expressed in thepositional notation

10011 = 1x20 +1x21 +0x22 +0x23 +1x24

The right-most is the least significant digit

The left-most is the most significant digit

• 8/6/2019 Binary Numbers Logic Operations

15/49

Binary (base 2) numbers are also

expressed in thepositional notation

10011 = 1x20 +1x21 +0x22 +0x23 +1x24

1s multiplier

1

• 8/6/2019 Binary Numbers Logic Operations

16/49

Binary (base 2) numbers are also

expressed in thepositional notation

10011 = 1x20 + 1x21 +0x22 +0x23 +1x24

2s multiplier

2

• 8/6/2019 Binary Numbers Logic Operations

17/49

Binary (base 2) numbers are also

expressed in thepositional notation

10011 = 1x20 +1x21 + 0x22 +0x23 +1x24

4s multiplier

4

• 8/6/2019 Binary Numbers Logic Operations

18/49

Binary (base 2) numbers are also

expressed in thepositional notation

10011 = 1x20 +1x21 +0x22 + 0x23 +1x24

8s multiplier

8

• 8/6/2019 Binary Numbers Logic Operations

19/49

Binary (base 2) numbers are also

expressed in thepositional notation

10011 = 1x20 +1x21 +0x22 +0x23 + 1x24

16s multiplier

16

• 8/6/2019 Binary Numbers Logic Operations

20/49

Counting

in Decimal0

1

23

4

5

6

7

8

9

10

11

1213

14

15

16

17

18

19

20

21

2223

24

25

26

27

28

29

30

31

3233

34

35

36

.

.

.

0

1

1011

100

101

110

111

1000

1001

1010

1011

11001101

1110

1111

10000

10001

10010

10011

10100

10101

1011010111

11000

11001

11010

11011

11100

11101

11110

11111

100000100001

100010

100011

100100

.

.

.

Counting

in Binary

• 8/6/2019 Binary Numbers Logic Operations

21/49

Why binaryBecause this system is natural for digital computersThe 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?

• 8/6/2019 Binary Numbers Logic Operations

22/49binary diginary digit

• 8/6/2019 Binary Numbers Logic Operations

23/49

Byte = 8 bits

• 8/6/2019 Binary Numbers Logic Operations

24/49

Decimal Binaryconversion

• 8/6/2019 Binary Numbers Logic Operations

25/49

Convert 75 to Binary

75237 12

18 12

9 02 4 12

2 02

1 02

0 1

1001011

remainder

• 8/6/2019 Binary Numbers Logic Operations

26/49

Check

1001011 = 1x20 + 1x21 + 0x22 + 1x23 +

0x24 + 0x25 + 1x26

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

= 75

• 8/6/2019 Binary Numbers Logic Operations

27/49

Convert 100 to Binary

100250 02

25 02

12 12 6 02

3 02

1 12

0 1

1100100

remainder

• 8/6/2019 Binary Numbers Logic Operations

28/49

That finishes our first topic - introduction

to binary numbers and theirconversion

to and from decimal numbers

Our next topic is

• 8/6/2019 Binary Numbers Logic Operations

29/49

Boolean

Logic

Operations

• 8/6/2019 Binary Numbers Logic Operations

30/49

Let

x,y,zbe 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 variablex,

we will assign a value of 0 tox when the

switch is OFF, and 1 when it is ON

• 8/6/2019 Binary Numbers Logic Operations

31/49

A few other names for the states

of these Boolean variables

0 1

Off On

Low High

False True

• 8/6/2019 Binary Numbers Logic Operations

32/49

• 8/6/2019 Binary Numbers Logic Operations

33/49

Well define these operations with the help of

truth tables

what is the truth tableofalogic function

A truth table defines the output of a

logic function forall possible inputs

?

• 8/6/2019 Binary Numbers Logic Operations

34/49

TruthTable for the NOTOperation

(y true whenever x is false)

x y = x

0

1

• 8/6/2019 Binary Numbers Logic Operations

35/49

• 8/6/2019 Binary Numbers Logic Operations

36/49

TruthTable for theAND Operation

(z true wh

en both

x & y true)

x y z = x y

0 0

0 1

1 01 1

• 8/6/2019 Binary Numbers Logic Operations

37/49

• 8/6/2019 Binary Numbers Logic Operations

38/49

TruthTable for the OR Operation

(z true wh

en x or y or both

true)

x y z = x +y

0 0

0 1

1 01 1

• 8/6/2019 Binary Numbers Logic Operations

39/49

TruthTable for the OR Operation

x y z = x +y

0 0 0

0 1 1

1 0 11 1 1

• 8/6/2019 Binary Numbers Logic Operations

40/49

TruthTable for the XOR Operation

(z true when x or y true, but not bot

h)

x y z = x y

0 0

0 1

1 01 1

• 8/6/2019 Binary Numbers Logic Operations

41/49

TruthTable for the XOR Operation

x y z = x y

0 0 0

0 1 1

1 0 11 1 0

• 8/6/2019 Binary Numbers Logic Operations

42/49

Those 4 were the fundamental logic operations.

Here are examples ofa few more complex situations

z = (x +y)

z = y(x

+y)

z = (y x) w

STRATEGY: Divide & Conquer

• 8/6/2019 Binary Numbers Logic Operations

43/49

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

0 0 0 1

0 1 1 0

1 0 1 01 1 1 0

z = (x +y)

• 8/6/2019 Binary Numbers Logic Operations

44/49

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

0 0 0 0

0 1 1 1

1 0 1 01 1 1 1

z = y (x +y)

• 8/6/2019 Binary Numbers Logic Operations

45/49

x y w y x z = (y x) w0 0 0 0 0

0 0 1 0 10 1 0 0 0

0 1 1 0 1

1 0 0 0 01 0 1 0 1

1 1 0 1 1

1 1 1 1 0

z = (y x) w

• 8/6/2019 Bina