chapter1 binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/fy92b-digital/chapter1.pdf ·...

38
1 Chapter 1 Binary Systems 1-1. Digital Systems The General-purpose digital computer is the best- known example of a digital system. The major parts of a computer are a memory unit , a central processing unit, and input-output units. Memory unit Control unit Input unit Output unit ALU unit Program data Program result Data Instruction Simplification of computer system

Upload: ngonguyet

Post on 15-Mar-2018

240 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

1

Chapter 1 Binary Systems1-1. Digital Systems

The General-purpose digital computer is the best-known example of a digital system.

The major parts of a computer are a memory unit ,a central processing unit, and input-output units.

Memory unit

Control unit

Input unit Output unit

ALU unit

Programdata

Programresult

Data

Instruction

Simplification ofcomputer system

Page 2: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

2

1-2. Binary Numbers A number with decimal point represented by a

series of coefficients as follow:

a5a4a3a2a1a0.a-1a-2a-3

the power of 10 by which the coefficient must bemultiplied as following:

105a5+104a4+103a3+102a2+101a1+100a0+10-1a-1+10-2a-2+10-3a-3

the decimal number system is said to be of base,and the coefficients are multiplied by powers of 10.

Page 3: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

3

Numbers convertion A number expressed in a base-r system has

coefficients multiplied by powers of r

anrn+an-1rn-1+…+a2r2+a1r+a0+a-1r-1+a-2r-2+…a-mr-m

Coefficients aj range in value from 0 to r-1.

Base-5 number:(4021.2)5

=4 X 53+0 X 52+2 X 51+1 X 50+2 X 5-1= (511.4)10

Others base-r number can be converted into decimalby this way.

Page 4: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

4

Numbers conversionBinary convert into decimal:(110101)2=32+16+4+1=(53)10

The number behind equal sign obtained asfollowing table

Page 5: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

5

Other operations Examples of addition, subtraction, and

multiplication of two binary numbers are as follows:

Augend: 101101 minuend: 101101 multiplicand: 101Addend:+100111 subtrahend:-100111 multiplier: X101Sum: 1010100 difference: 000110 101

011001 000101

product: 11001Find 2’s complementthen add withminuend(section 1-5)

Page 6: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

6

1-3. Number base conversions

Ex1-1:Convert decimal 41 to binaryInteger Remainder2 41

20 110 05 02 11 0

The conversion from decimal integers to any base-r systemis similar to the example, see the Ex1-2.

Answer=101001

Page 7: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

7

Number base conversions Ex1-3:Convert (0.6875)10to octal

Integer Fraction Coefficient0.6875 X 2 = 1 + 0.3750 a-1=10.3750 X 2 = 0 + 0.7500 a-2=00.7500 X 2 = 1 + 0.5000 a-3=10.5000 X 2 = 1 + 0.0000 a-4=1

The answer is (0.6875)10 = (0. a-1a-2a-3a-4)2 = (0.1011)2

To convert a decimal fraction in base-r, a similar procedureis used. Combining the answer from Ex1-1 and Ex1-3

(41.6875)10 = (101001.1011)2

Page 8: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

8

1-4. Octal and hexadecimalnumbers

Page 9: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

9

1-4. Octal and hexadecimalnumbers

( 10 110 001 101 011 . 111 100 000 110 )2 = ( 26153.7460)8

( 10 1100 0110 1011 . 1111 0010 )2 = ( 2C6B.F2)16

(673.124)8 = ( 110 111 011 . 001 010 100 )2

( 306.D)16 = ( 0011 0000 0110 . 1101 )2

Page 10: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

10

1-5. Complements Complements are used for simplifying the

subtraction operation and for logicalmanipulation.

There are two types of complements for eachbase-r system: the radix and the diminishedradix complements.

Binary numbers: 2’s complement1’s complement

Decimal numbers:10’s complement9’s complement

Page 11: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

11

Diminished radix complement Given a number N in base-r having n digits, the

(r-1)’s complement of N is defined as (rn-1)-N.

Decimal numbers: 012398 have 6 digits and present below

(106 - 1) –012398 = 999999 –012398 = 987601

Binary numbers: 1011000=(88)10

(27 - 1) –1011000 = 1111111 –1011000 = 0100111(39)

shortcut(1<-->0) 0100111

Page 12: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

12

Radix complement The r’s complement of an n-digit number in base-r

is defined as rn −N, for N=0 and 0 for N=0. Compare with (r −1)’s complement, the r’s

complement is (r −1)’s + 1 sincern −N=[(rn −1) −N] + 1.

Decimal number: 012398106 − 012398 = 987602 = 999999 −012398 + 1

Binary number: 1011000(88)27 −1011000=0101000(38)=1111111 −1011000+1

Or 1011000 Leaving all least significant 0’s and the first 1unchanged, and others have complemented

unchangedcomplemented

Page 13: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

13

Subtraction with complements The subtraction of two n-digit unsigned numbers

M −N in base-r can be done as follows:

1. Add the minuend, M, to the r’s complement of thesubtrahend, N. This performs M + (rn −N) = M −N + rn.

2. If M≥N, sum will produce an end carry, rn, which can bediscarded; the result is M −N.

3. If M<N, the sum does not produce an end carry and isequal to rn −(N −M). Take the r’s complement of the sumand place a negative sign in front.

Page 14: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

14

ExamplesEx1-6: 3250 −72532 using 10’s complement

M = 0325010’s complement of N = + 27468

Sum= 30718 no end carry

The answer is −(10’s complement of 30718) = −69282

Ex1-7: X=1010100, Y=1000011 using 2’scomplement(b) Y = 10000112’s complement of X = +0101100

Sum = 1101111 no end carryThe answer is Y−X =−(2’s complement of 1101111)=−0010001

Page 15: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

15

Examples We can also use (r −1)’s complement, the sum is 1

less than the correct difference when an end carryoccurs. Removing the end carry and adding 1 tothe sum is referred to as an end-around carry.

Ex1-8: Repeat Ex1-7 using 1’s complement(a) X = 10101001’s complement of Y = + 0111100

Sum = 10010000End around carry = + 1

Answer : X −Y = 0010001

Page 16: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

16

1-6. Signed binary numbers

The convention is to make the sign bit 0 forpositive and 1 for negative in Signed binarynumbers.

In signed binary, the leftmost bit represents thesign and the rest of the bits represent the number.

In unsigned binary, the leftmost bit is the mostsignificant bit(MSB).

In 2’s complement could represent one more thannegative number because of no negative zero.

Page 17: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

17

Identical

MSB is 1 todistinguishthem fromthe positivenumbers

Page 18: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

18

Arithmetic of subtraction andaddition

We have discussed at section 1-5 and havefollowing conclusion:

2’s complement:1. Have an end carry, discard then get answer2. No end carry, find 2’s complement and add minus sign

front the answer1’s complement:1. Have an end around carry, add this bit then get answer2. No end around carry, find 1’s complement and add minus

sign front the answer

Page 19: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

19

1-7. Binary codesBCD code

We are more accustomed tothe decimal system, and isstraight binary assignment aslisted in Table1-4. this iscalled binary codeddecimal(BCD).

1010~1111 are not used andhave no meaning in BCD code.

Ex:(185)10=(1011001)2=(0001 1000 0101)BCD

Page 20: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

20

BCD Addition When the binary sum is greater than or equal to

1010, the addition of 6 to the binary sum convertsit to the correct digit and also produces a carry asrequired.

One digit addition: two digits addition:1000 8 BCD carry 1 1

+1001 +9 0001 1000 0100 18410001 17 +0101 0111 0110 +576+0110 Binary sum 0111 10000 10101 0111 Add 6 0110 0110

BCD sum 0111 0110 0000 760

>9

+6

Page 21: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

21

Other Decimal Codes The BCD,84-2-1, and the 2421 codes are

examples of weighted codes.

The 2421 and the excess-3 codes are examples ofself-complementing codes.

Ex. (395)10 = (0110 1100 1000)excess-3

9’s complement self-complementing

(604)10 = (1001 0011 0111)excess-3

it is obviously to know the self-complementing that theexcess-3 code of 9’s complement of 395 is complementingthe excess-3 of 395 directly. So does the 2421 code.

Page 22: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

22

Other Decimal CodesTable1-5Four Different Binary Codes for the Decimal DigitsDecimal BCDDigit 8421 2421 Excess-3 8 4-2-10 0000 0000 0011 0 0 0 01 0001 0001 0100 0 1 1 12 0010 0010 0101 0 1 1 03 0011 0011 0110 0 1 0 14 0100 0100 0111 0 1 0 05 0101 1011 1000 1 0 1 16 0110 1100 1001 1 0 1 07 0111 1101 1010 1 0 0 18 1000 1110 1011 1 0 0 09 1001 1111 1100 1 1 1 1

1010 0101 0000 0 0 0 1Unused bit 1011 0110 0001 0 0 1 0Combinations 1100 0111 0010 0 0 1 1

1101 1000 1101 1 1 0 01110 1001 1110 1 1 0 11111 1010 1111 1 1 1 0

2 x 1+4 x 1+2 x 0+1 x 1=7

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

weight

Page 23: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

23

Gray Code

The advantage of the Graycode over the straightbinary number sequence isthat only one bit in thecode group changes whenone number to the next.

EX: from 7 to 8Gray code changes from0100 to 1100.

(0 1 1 1)2

xor

(01 0 0)Gray

xor

(01 1 1)2

Page 24: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

24

ASCII Character Code ASCII include seven bits, contain 94 graphic

characters and 34 control functions as followstable.

There are three types of control characters:1. format effectors: control the layout of printing (BS, HT,

CR…).2. information separators: used to separate the data into

divisions such as paragraphs and pages (RS, FS…).3. communication-control characters: it is useful during the

transmission of text between remote terminals (STX,ETX..).

Page 25: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

25

ASCII Table

Page 26: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

26

Control characters

Page 27: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

27

Error Detecting Code An eighth bit is added to the ASCII character to

indicate its parity. We have following even and oddparity:

with even parity with odd parityASCII A=1000001 01000001 11000001ASCII T=1010100 11010100 01010100

The even or odd parities can find out only oddcombination of errors in each character, an evencombination of errors is undetected. May be thehamming code can solve that in some bits range.

Page 28: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

28

1-8. Binary storage andregisters

A binary cell is a device that processes two stablestates and is capable of storing one bit of info, anda register is a group of binary cells.

Bit cell

Input AND3

NOT2

S

R Q_Q

SRFFNOT1 AND2

AND1

Select

Rd/We

Output

Page 29: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

29

Register

Input AND3

NOT2

S

R Q_Q

SRFFNOT1 AND2

AND1

Select

Rd/We

Output

Input AND3

NOT2

S

R Q_Q

SRFFNOT1 AND2

AND1

Select

Rd/We

Output

Input AND3

NOT2

S

R Q_Q

SRFFNOT1 AND2

AND1

Select

Rd/We

Output

Input AND3

NOT2

S

R Q_Q

SRFFNOT1 AND2

AND1

Select

Rd/We

Output

Input AND3

NOT2

S

R Q_Q

SRFFNOT1 AND2

AND1

Select

Rd/We

Output

Input AND3

NOT2

S

R Q_Q

SRFFNOT1 AND2

AND1

Select

Rd/We

Output

Input AND3

NOT2

S

R Q_Q

SRFFNOT1 AND2

AND1

Select

Rd/We

Output

Input AND3

NOT2

S

R Q_Q

SRFFNOT1 AND2

AND1

Select

Rd/We

Output

Decoder1X2

Read/Write

4bit Register

Page 30: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

30

Register Transfer

1234

Decoded

parity

Clear

J O H N

ASCII with odd

Page 31: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

31

Binary information processing

Operand 2

Operand 1

0 0 0 1 0 0 0 0 1 0

0 0 1 1 1 0 0 0 0 1

0 1 0 0 1 0 0 0 1 1

0 1 0 0 1 0 0 0 1 1Sum

Page 32: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

32

1-9. Binary Logic

There are three basic logical operations:1. AND: This operation is represented as follows

x . y = z or x y = z,z=1 if and only if x=1 and y=1; otherwise z=0

2. OR: This operation is represented as followsx + y = z

z=1 if x=1 or if y=1 or x=1 and y=1 ;otherwise z=03. NOT: This operation is represented as follows

x’= z or x = ze.g. complement operation, changes a 1 to 0, 0 to 1

Page 33: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

33

Similar and difference Binary logic resembles binary arithmetic, and the

operations AND and OR have similarities tomultiplication and addition, respectively.

The symbols used for AND and OR are the same asthose used for multiplication and addition.

Binary logic should not be confused with binaryarithmetic.

Binary arithmetic: 1 + 1 = 102=(2)10

Binary logic: 1 + 1 = 12

Page 34: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

34

Logic Gates

For eachcombination of thevalues of x and y,and output z, it maybe listed in acompact form usingtruth tables.

Page 35: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

35

Definition of the logic signals

Logic gates are electroniccircuits that operate onone or more input signalsto produce an outputsignal.

Signals such as voltagesor currents, we definebetween some ranges aslogic 1 or logic 0.

Page 36: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

36

The symbol of logic gates

The graphic symbols used to designate thethree types of gates are shown below.

Page 37: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

37

Timing diagrams

0

0

0

0

1

0

1

0

1

00

1

1

1

1 0

0

0

1

0

1

0

1

0

1

Page 38: Chapter1 Binary systems - 國立中興大學web.ee.nchu.edu.tw/~cpfan/FY92b-digital/Chapter1.pdf · Chapter 1 Binary Systems ... 1-4. Octal and hexadecimal ... (673.124) 8 = ( 110

38

Gates with multiple inputs AND and OR gates may have more than two inputs. Three –input AND gate responds with logic 1 output if all

three inputs are logic 1. when any input is logic 0, outputproduces logic 0.

OR gate characteristic have described before in thischapter.