chapter 1: number systems and codes. introduction digital circuits, processing discrete information,...

Post on 18-Jan-2016

247 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CHAPTER 1: Number CHAPTER 1: Number Systems and CodesSystems and Codes

IntroductionIntroduction

Digital circuits, processing discrete information, Digital circuits, processing discrete information, are found in an astonishingly wide rang of electronic are found in an astonishingly wide rang of electronic systems. They have provided system designers with systems. They have provided system designers with more functions contained in less space, thereby more functions contained in less space, thereby improving system reliabilityimproving system reliability and and increasing speedincreasing speed. . Digital systems operate on numbers that represent some Digital systems operate on numbers that represent some real logical or arithmetic function. It is the designer’s real logical or arithmetic function. It is the designer’s task to establish the relationship between the numbers task to establish the relationship between the numbers and the task being performed. This chapter develops and the task being performed. This chapter develops the use of numbers and how they represent real world the use of numbers and how they represent real world conditions in digital system.conditions in digital system.

1.1 Digital and Analog: Basic 1.1 Digital and Analog: Basic ConceptsConcepts

ContinuousContinuous: Without breaks, smooth, no interruptions; a range of values forming a line or curve without gaps or discontinuities

DiscreteDiscrete: Broken down into pieces; opposite of continuous; a single part or point that can unambiguously be defined

1.1 Digital and Analog: Basic 1.1 Digital and Analog: Basic ConceptsConcepts

AnalogAnalog: Refer to something that is analogous, has a likeness, or is similar to something else. Analog electronic signals are continuous, whereas voltage( 电压 ), current( 电流 ), or some other electrical parameter is used to represent a physical parameter. For instance, voltage changes may represent changes in temperature.

DigitalDigital: Refer to digits or numbers in any radix; digital electronics usually involves binary or base-2 number systems. Digital signals are discrete, not continuous

1.1 Digital and Analog: Basic 1.1 Digital and Analog: Basic ConceptsConcepts

1.1 Digital and Analog: Basic 1.1 Digital and Analog: Basic ConceptsConcepts

Vc(0)=0V, Initial voltage at t0 is 0V

Vc=Va(1-e-t/RC)

1.1 Digital and Analog: Basic 1.1 Digital and Analog: Basic ConceptsConcepts

(a) Analog representation

(b) Discrete representation

Discrete voltage values for time interval

1.1 Digital and Analog: Basic 1.1 Digital and Analog: Basic ConceptsConcepts

Analog volt meter

Digital volt meter

Analog VS DigitalAnalog VS Digital

Analog VS DigitalAnalog VS Digital

Digital Circuits over Analog OnesDigital Circuits over Analog Ones: -- Reproducibility of Results -- Ease of design, Flexibility and Functionality -- Programmability -- Speed, Economy and Steadily Advancing Technology

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

SSI (small-scale integration) contains 0-9 gates

MSI (medium-scale integration) contains 10-99gates

LSI (large-scale integration) contains 100 or more gates

VLSI (very large-scale integration ) contains more than 1000 gates

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

1.2 Digital Systems Overview1.2 Digital Systems Overview

Samsung LN40A750 40-Inch 1080p DLNA LCD HDTV

ARM Powered

Amazon Kindle2 e-book reader

ARM PoweredFreescale

Parrot : Zikmu Wireless speakers by Philppe Starck

ARM926 Processor

Palm Pre

ARM Cortex A8

Texas Instruments OMAP3430

Nintendo DSi

ARM9 and ARM7 Processors

Konica Minolta Magicolor 1650EN Printer

ARM11 Processor

Zoran Corporation Quatro 4230 Processor

iRiver Wave Home (Multimedia Communicator)

ARM PoweredHP mv5150 Media Vault Pro

ARM9 Processorr

Marvell Orion (88F5182-A2) Processor

APSI M-480 PMP

ARM11 Processor

TI OMAP2530 Dual-Core CPU

TeleNav Shotgun

ARM926 Processor

SiRF Atlas III

Kangaroo TV

ARM926EJ-s

Freescale i.MX21 Processor

Zeebo Console

ARM11 Processor and ARM9 Processor

Qualcomm

Dell Latitude E4200 Notebook

ARM Cortex M3

Broadcom BCM5880

1.3 Introduction to Number System1.3 Introduction to Number System

Digital systems represented information in a discrete form, and Number systems provide the means of quantifying information

for processing by digital system. – Positional Number Systems– Number system conversion– Binary Codes– Arithmetic

Number Systems - DecimalNumber Systems - Decimal

“base” 10 (radix is 10) 10 digits: 0..9

536.15910=(5×102)+(3×101)+(6×100)+(1×10-1)+(5×10-2)+(9×10-3)

WeightWeightRadix or BaseRadix or Base

Number Systems – Decimal (cont.)Number Systems – Decimal (cont.)

In general, a decimal number with n digits to the left of the decimal point, and m digits to the right of the decimal point is written as:

An-1 An-2 … A1 A0 . A-1 A-2 … A-m+1 A-m

where Ai is a coefficient between 0..9,

and i denotes the weight (=10i) of Ai.

Number Systems – GeneralNumber Systems – General

“base” r (radix r) r digits N = An-1 ×r n-1 + An-2 × r n-2 +… + A1 × r + A0 +

A-1 × r -1 + A-2 × r -2 +… + A-m × r -m

MostSignificant Bit (MSB)

LeastSignificantBit (LSB)

Let r=radix or base of a number system;

Let c=character from the character set of the radix;

Let N=number to be represented in radix;

Let n=the number of digits in the integer portion of N

Let m=the number of digits in the fractional portion of N

(N)(N)rr=(c=(cn-1n-1rrn-1n-1+c+cn-2n-2rrn-2n-2+…+c+…+c11rr11+c+c00rr00+c+c-1-1rr-1-1+c+c-2-2rr-2-2+…+c+…+c-m-mrr-m-m))

(N)r= c(N)r= ciirrii∑n=1

i=-m

Positional Number SystemsPositional Number Systems

Number Systems – General (cont.)Number Systems – General (cont.)

e.g. let r = 6

(312.4)6 = 3 × 62 + 1 × 61 + 1 × 60 + 4 × 6-1

= (116.66)10

Conversion from n-radix (any system with radix n) to decimal follows similar process as above

Number Systems (cont.)Number Systems (cont.)

Most common number systems for computers:Binary (r = 2)Octal (r = 8)Hexadecimal (r = 16)

Binary Numbers--Base 2Binary Numbers--Base 2

Computers represent all data as “strings of bits”, each bit being either 0 or 1

“base” 2, with 2 digits: 0 and 1

e.g. (101101.10)2 = 1×25 + 0×24 + 1×23 + 1×22 + 0×21 +

1×20 + 1×2-1 + 0×2-2

(in decimal) = 32 + 0 + 8 + 4 + 0 + 1 + ½ + 0

= (45.5)10

Powers of twoPowers of two

Memorize at least through 216

Octal Numbers--Base 8Octal Numbers--Base 8

“base” 8 with 8 digits: 0..7

Eg.

231.258=2×82 + 3×81+1×80+2×8-1+5×8-2

(in decimal) =153.32812510

Hexadecimal Numbers--Base 16Hexadecimal Numbers--Base 16

r = 16 Digits (convention): 0..9, A, B, C, D, E, F A=10, B=11, … , F = 15

Hexadecimal Decimal

A 10B 11C 12D 13E 14F 15

e.g1. (3FB)16 = 3×162 + 15×161 + 11×160 (in decimal) = 768 + 240 + 11

= (1019)10

e.g2.

A59C.3A16 = (A×163)+(5×162)+(9×161)+(C×160)+(3×16-1)+(A×16-2)

1.3.2 Number System Conversion1.3.2 Number System ConversionDecimal , binary,octal,and

hexadecimal number

Binary Binary Octal Octal

(011 010 101 000 . 111 101 011 100)2

( 3 2 5 0 . 7 5 3 4 )8

E.g.E.g. Convert the binary number

010011110111.1101010102to octal

Solution 010,011,110,111.110,101,0102=2367.6528

Binary Binary Hex Hex

( 6 A 8 . F 5 C )16

( 0110 1010 1000 . 1111 0101 1100 )2

E.g.E.g. Convert the binary number

010011110111.1101010102to hexadecimal

Solution 0100,1111,0111.1101,0101,00002=4F7.D5016

1.3.2 Number System Conversion1.3.2 Number System Conversion hexadecimal and octal to Binary Conversionhexadecimal and octal to Binary Conversion

E.g. Convert the numbers F37A.B216,735.58 to binary

Solution F37A.B2=1111,0011,0111,1010.1011,00102

735.58 =111,011,101.1012

Practice problem: convert 367.2368to binary then hexadecimal

Solution 367.2368=011,110,111.010,011,1102

011,110,111.010,011,1102=0,1111,0111.0100,1111,02=F7.4F16

1.3.2 Number System Conversion1.3.2 Number System Conversion

Binary to decimal ConversionBinary to decimal Conversion

11001.0112

=(1×24)+(1×23)+(0×22)+(0×21)+(1×20) +(0× 2-1)+(1×2-2)+(1×2-3)

=16+8+0+0+1+0+0.25+0.125

=25.37510

1.3.2 Number System Conversion1.3.2 Number System Conversiondecimal to Binary Conversiondecimal to Binary Conversion

•Successive Division Radix ConversionSuccessive Division Radix Conversion

592 119 118 1 1

292 59 58 1 1

142 29 28 1 1

72 14 14 0 0

32 7 6 1 1

12 3 2 1 1

02 1 0 1 1

( LSB )

( MSB )

E.g. Convert 11910 to binary

11910=11101112

Solution

1.3.2 Number System Conversion1.3.2 Number System ConversionDecimal to Binary ConversionDecimal to Binary Conversion

•Fractional Radix Conversion, Successive MultiplicationFractional Radix Conversion, Successive Multiplication

E.g. Convert .7510 to binary

Multiply .75 by 2 (.75)2=1.5 1(MSB)

Multiply .75 by 2 (.5)2=1.0 1

Multiply .75 by 2 (0)2=0.0 0(LSB)

Solution

.7510=.110=(1)2-1+(1)2-2

E.g. Convert 95.062510 to binary ( con. )

1.3.2 Number System Conversion1.3.2 Number System Conversion

Solution First, convert the integer part of the decimal number by successive division

47 2 95 94 1 1

23 2 47 46 1 1

11 2 23 22 1 1 5 2 11 10 1 1

1 2 2 2 0 0

2 2 5 4 1 1

0 2 1 0 1 1

1.Devide 95 by 2

4.Devide 11 by 2

3.Devide 23 by 2

2.Devide 47 by 2

5.Devide 5 by 2

6.Devide 2 by 2

7.Devide 1 by 2

(LSB)

(MSB)

9510=1·26+0·25+1·24+1·23+1·22+1·21+1·20

1.3.2 Number System Conversion1.3.2 Number System Conversion E.g. Convert 95.062510 to binary ( con. )

Second, convert the fraction

1. (.625)2=0.125 0 (MSB)

2. (.125)2=0.25 0

3. (.25)2=0.5 0

4. (.5)2=1.0 1 (LSB)

.062510=.00012

95.062510=1011111.00012

1.3.2 Number System Conversion1.3.2 Number System ConversionDecimal to Any RadixDecimal to Any Radix

The conversion of decimal numbers to any other radix applies the successive division and successive multiplication algorithms

e.g.e.g. Convert 23.62510 to octal (base 8)

SolutionSolution

2 8 23 16 7 7

0 8 2 0 2 2

1.Divide 23 by 8

2.Divide 2 by 8

(LSB)(LSB)

(MSB)(MSB)

2310=278

Convert the integer portion by successive division

Convert te fraction portion by successive multiplication

(.625)8=5.00 5 (MSB)(MSB)

.62510=.58

23.62523.6251010=27.5=27.588

1.3.2 Number System Conversion1.3.2 Number System ConversionAny Radix to DecimalAny Radix to Decimal

e.g.e.g. Convert 324.25 to decimal

Solution Solution 3·52+2·51+4·50+2·5-1

=3(25)+2(5)+4(1)+2(1/5)

=75+10+4+2/5

=89.410

1.3.2 Number System Conversion1.3.2 Number System Conversion

Practice problem: 1. Convert 345.26 to decimal

2. Convert 34.810 to base 5

Solution:Solution: 1. 137.333……10

2. 114.45

1.3.3 Binary Codes1.3.3 Binary CodesNatural Binary Coded DecimalNatural Binary Coded Decimal

Decimal to natural BCDDecimal to natural BCD

e.g.e.g. Convert 9275.610 into BCD

9=1001

2=0010

7=0111

5=0101

6=0110

9275.610=1001 , 0010 , 0111 , 0101.0110 in BCD

Solution:Solution:

1.3.3 Binary Codes1.3.3 Binary CodesBinary Codes (Weighted)Binary Codes (Weighted)

1.3.3 Binary Codes1.3.3 Binary Codes Unit Distance Code: Gray codeUnit Distance Code: Gray code

Timing diagram illustrating potential error when two bits change sat the same time

1.3.3 Binary Codes1.3.3 Binary Codes Unit Distance Code: Gray codeUnit Distance Code: Gray code

Three-bit and Three-bit and Four-bit Gray Four-bit Gray codecode

1.3.3 Binary Codes1.3.3 Binary Codes Alphanumeric codesAlphanumeric codes

ASCIIASCII (American standard code for information interchange)

EBCDIC EBCDIC (extended BCD interchange code)

Partial listing of seven-bit ASCII and eight-bit EBCDIC codes in hexadecimal

1.3.3 Binary Codes1.3.3 Binary Codes Signed Number BinarySigned Number Binary

Binary signed magnitude Binary signed magnitude number convention uses the number convention uses the most significant bit position most significant bit position to indicate sign and the to indicate sign and the remaining lesser significant remaining lesser significant bits to represent magnitudebits to represent magnitude

Sign magnitude and complement

Sign magnitude

2s complement

1s complement

Signed Number RepresentationSigned Number Representation Signed Magnitude MethodSigned Magnitude Method

N = (s,an-1 ... a0.a-1 ... a-m)rsm,

where s = 0 if N is positive and s = r -1 otherwise.– E.g. N = -(15)10

In binary: N = -(15)10 = -(1111)2 = (1, 1111)2sm

In decimal: N = -(15)10 = (9, 15)10sm

Complementary Number SystemsComplementary Number Systems– Radix complements (r's complements)

[N]r = rn - (N)r

where n is the number of digits in (N)r.

– Diminished radix complements (r-1’s complements)

[N]r-1 = rn - (N) r - 1

Radix Complement Number SystemsRadix Complement Number Systems

2's complement of (N)2 = (101001)2

[N]2 = 26 - (101001)2 = (1000000)2 - (101001)2 = (010111)2

(N)2 + [N]2 = (101001)2 + (010111)2 = (1000000)2

If we discard the carry, (N)2 + [N]2 = 0.

Hence, [N]2 can be used to represent -(N)2.

[ [N]2 ]2 = [(010111)2]2 = (1000000)2 - (010111)2 = (101001)2 = (N)2.

2's complement of (N)2 = (1010)2 for n = 6

[N]2 = (1000000)2 - (1010)2 = (110110)2.

10's complement of (N)10 = (72092)10

[N]10 = (100000)10 - (72092)10 = (27908)10.

Radix Complement Number SystemsRadix Complement Number Systems AlgorithmAlgorithm : : Find [N]Find [N]rr given (N) given (N)rr . .

1.Copy the digits of N, beginning with the LSB and proceeding toward the MSB until the first nonzero digit, aj, has been reached

2.Replace aj with r - aj.

3.Replace each remaining digit aj , of N by (r - 1) - aj until the MSB has been replaced.

– Example: 10's complement of (56700)10 is (43300)10

– Example: 2's complement of (10100)2 is (01100)2.

– Example: 2’s complement of N = (10110)2 for n = 8.

• Put three zeros in the MSB position and apply algorithm• N = 00010110

• [N]2 = (11101010)2

Radix Complement Number SystemsRadix Complement Number Systems Algorithm2Algorithm2 : : Find [N]Find [N]rr given (N) given (N)rr . .

First replace each digit, ak , of (N)r by (r - 1) - ak and then add

1 to the resultant.

Example: Find 2’s complement of N = (01100101)2 .

N = 01100101

10011010 Complement the bits

+1 Add 1

[N]2 = (10011011)2

Example: Find 10’s complement of N = (40960)10

N = 40960

59039 Complement the bits

+1 Add 1

[N]2 = (59040)10

Radix Complement Number SystemsRadix Complement Number Systems 2's complement number system

– Positive number : • N = +(an-2, ..., a0)2 = (0, an-2, ..., a0)2cns,

where .– Negative number:

• N = (an-1, an-2, ..., a0)2 • -N = [an-1, an-2, ..., a0]2 (two's complement of N),

where .

– Example: Two's complement number system representation of (N)2

when (N)2 = (1011001)2 for n = 8:• +(N)2 = (0, 1011001)2cns

• -(N)2 = [+(N)2]2 = [0, 1011001]2 = (1, 0100111)2cns

11 2nN

10 2 1nN

Diminished Radix Complement Diminished Radix Complement Number systemsNumber systems

Diminished radix complement [N]r-1 of a number (N)r is:

[N]r-1 = rn - (N)r - 1

One’s complement (r = 2):

[N]2-1 = 2n - (N)2 - 1

Example: One’s complement of (01100101)2

[N]2-1 = 28 - (01100101)2 - 1

= (100000000)2 - (01100101)2 - (00000001)2

= (10011011)2 - (00000001)2

= (10011010)2

Radix Complement Number SystemsRadix Complement Number Systems

QuziQuzi ::Find the 2s complement of the binary number 110011Find the 1s complement code for -1210

Find the 2s complement code for -1810

Answer: 001101Answer: 001101

1001110011

101110101110

1.3.4 Binary Arithmetic Using 1.3.4 Binary Arithmetic Using Complement CodesComplement Codes

(+X)+(+Y)

(+X)+(-Y)

(-X)+(+Y)

(-X)+(-Y)

(+X)-(+Y)

(+X)-(-Y)

(-X)-(+Y)

(-X)-(-Y)

+(X+Y)

-(X+Y)

+(X+Y)

-(X+Y)

+(X-Y)

-(X-Y)

+(X-Y)

-(X-Y)

-(X-Y)

+(X-Y)

-(X-Y)

+(X-Y)

+(X-Y)

+(X-Y)

+(X-Y)

+(X-Y)

Operation Add X>Y X=YX<Y

Subtract

Addition and subtraction of signed numbersAddition and subtraction of signed numbers

9+3=12 ( -9 ) + ( -3 ) =-12 0^1001 1^0111 ( -9 )+ 0^0011 + 1^1101 ( -3 ) 0^1100 1 1^0100 ( -12 )

9-3=6 9- ( -3 ) =12 0^1001 0^1001 + 1^1101 + 0^0011 1 0^ 0110 0^1100

3-9=-6 0^0011

+ 1^0111 1^1010

1.3.4 Binary Arithmetic Using 1.3.4 Binary Arithmetic Using Complement CodesComplement Codes

e.g.e.g.

e.g. 0^1101.1+0^1011.0e.g. 0^1101.1+0^1011.0

1.3.4 Binary Arithmetic Using 1.3.4 Binary Arithmetic Using Complement CodesComplement Codes

0^01101.1

+ 0^01011.0

0^11000.1

0^1101.1

+ 0^1011.0

1^1000.1

The The errorerror occurred due to insufficient occurred due to insufficient bit positions to hold the answerbit positions to hold the answer

e.g. Add X and Y . Let X=-810 and Y=-1010, both in 2s complement

1.3.4 Binary Arithmetic Using 1.3.4 Binary Arithmetic Using Complement CodesComplement Codes

1^1000

+ 1^0110

(1)0^1110

1^11000

+ 1^10110

(1)1^01110

-8-81010+(-10+(-101010)=-18)=-1810 10 , 0^1110 is not -18, 0^1110 is not -1810 10 and and

1^01110 is the Complement of -181^01110 is the Complement of -181010

e.g. Subtract Y from X. Let X=+810=0^1000 and Y=-610=1^1010, X-Y=X+(-Y)

1.3.4 Binary Arithmetic Using 1.3.4 Binary Arithmetic Using Complement CodesComplement Codes

0^1000 = +810

+ 0^0110 =(complement of -6 )

0^1110 =+1410

0^1000=+810

The 2s complement of -610(1^1010) is 0^0110

1.3.4 Binary Arithmetic Using 1.3.4 Binary Arithmetic Using Complement CodesComplement Codes

exe. Subtract Y from X. Let X=-1010=1^0110 and Y=-510=1^1011

1^0110 = -1010

+ 0^0101 =(complement of -510 )

1^1011 =-510

The radix complement of 1^1011(-510) is 0^0101

1.3.4 Arithmetic Using Complement 1.3.4 Arithmetic Using Complement CodesCodes

Exe : perform the following operations by finding the radix complement of the subtrahend( 减数 ) and adding the result to the minuend( 被减数 ):

23.410 135.78 321.24

- 19.810 - 67.78 - 33.34

top related