number systems and codes

44
NUMBER SYSTEMS AND CODES

Upload: hermione-christensen

Post on 03-Jan-2016

75 views

Category:

Documents


5 download

DESCRIPTION

NUMBER SYSTEMS AND CODES. Outline. Number systems Number notations Arithmetic Base conversions Signed number representation Codes Decimal codes Gray code Error detection code ASCII code. Number Systems. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: NUMBER SYSTEMS  AND  CODES

NUMBER SYSTEMS AND

CODES

Page 2: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 2

Outline

• Number systems– Number notations– Arithmetic– Base conversions – Signed number representation

• Codes– Decimal codes– Gray code– Error detection code– ASCII code

Page 3: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 3

Number Systems

The decimal (real), binary, octal, hexadecimal number systems are used to represent information in digital systems. Any number system consists of a set of digits and a set of operators (+, , , ).

Page 4: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 4

Radix or Base 

 

 

 

Decimal (base 10) 0 1 2 3 4 5 6 7 8 9

Binary (base 2) 0 1

Octal (base 8) 0 1 2 3 4 5 6 7

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

The radix or base of the number system denotes the number of digits used in the system.

Page 5: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 5

Decimal Binary Octal Hexadecimal

00 0000 00 0

01 0001 01 1

02 0010 02 2

03 0011 03 3

04 0100 04 4

05 0101 05 5

06 0110 06 6

07 0111 07 7

08 1000 10 8

09 1001 11 9

10 1010 12 A

11 1011 13 B

12 1100 14 C

13 1101 15 D

14 1110 16 E

15 1111 17 F

Page 6: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 6

Positional Notation

It is convenient to represent a number using positional notation. A positional notation is written as a sequence of digits with a radix point separating the integer and fractional part.

   where r is the radix, n is the number of digits of

the integer part, and m is the number digits of the fractional part.

rmnnr aaaaaaaN 210121 .

Page 7: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 7

Polynomial Notation

A number can be explicitly represented in polynomial notation.

 

 

where rp is a weighted position and p is the position of a digit.

mm

nn

nnr rararararararaN

22

11

00

11

22

11

Page 8: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 8

Examples

In binary number system

 

In octal number system

In hexadecimal number system

321012342 2121202021202121011.11010

3210128 848281838786124.673

101216 16166160163.306 DD

Page 9: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 9

Arithmetic

(101101)2 +(11101)2 : 1111 1

 + 101101

11101

  1001010

Addition:

In binary number system,

Page 10: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 10

Addition

(6254)8+(5173)8 : 1 1

 + 6254

5173

  13447

In octal number system,

(9F1B)16 +(4A36)16 : 1 1

 + 9F1B

4A36

  D951

In hexadecimal number system,

Page 11: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 11

Subtraction

(101101)2 -(11011)2 : 10 10

 - 101101

11011

  10010

In binary number system,

Page 12: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 12

Subtraction

In octal number system,

In hexadecimal number system,

(6254)8 -(5173)8 : 8

 - 6254

5173

  1061

(9F1B)16 -(4A36)16 : 16

 - 9F1B

4A36

  54E5

Page 13: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 13

Multiplication

(1101)2 (1001)2 :

1101

1001

1101

0000

  0000

1101

  1110101

In binary number system,

Page 14: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 14

Division

(1110111)2 (1001)2 :

1101

1001 1110111

1001

  1011

1001

   1011

1001

  10

In binary number system,

Page 15: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 15

Base Conversions

Convert (100111010)2 to base 8

8

012

01112

0123456782

472

828784

8281828484

202120212121202021100111010

8

22

472274

010111100100111010

Page 16: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 16

Base Conversion

Convert (100111010)2 to base 10

10

1010101010

0123456782

314

281632256

202120212121202021100111010

Page 17: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 17

Base Conversion

Convert (100111010)2 to base 16

16

012

00112

0123456782

13

16163161

162168161162161

202120212121202021100111010

A

A

16

22

1331

101000110001100111010

AA

Page 18: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 18

Base Conversion from base 8

• Convert (372)8 to base 2

• Convert (372)8 to base 10

• Convert (372)8 to base 16

2

8

11111010010111011

273372

10

101010

0128

250

256192

828783372

16

28 10101111372

FAAF

Page 19: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 19

Base Conversion from base 16

• Convert (9F2)16 to base 2

• Convert (9F2)16 to base 8

• Convert (9F2)16 to base 10

2

16

101001111100001011111001

2929

FF

82

16

4762)2

0106

1107

1114

100(001011111001

2929

FF

10

101010

01216

2546

22402304

1621616929

FF

Page 20: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 20

Binomial expansion (series substitution)

To convert a number in base r to base p.– Represent the number in base p in binomial

series.– Change the radix or base of each term to base p.– Simplify.

Page 21: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 21

Convert Base 10 to Base r

Convert (174)10 to base 8

Therefore (174)10 = (256)8

8 1 7 4 6 LSB

  8 2 1 5  

    8 2 2 MSB

      0 0  

Page 22: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 22

Convert Base 10 to Base r

Convert (0.275)10 to base 8

Therefore (0.275)10 = (0.21463)8

8 0.275 2.200 MSD

8 0.200 1.600  

8 0.600 4.800  

8 0.800 6.400  

8 0.400 3.200 LSD

Page 23: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 23

Convert Base 10 to Base r

Convert (0.68475)10 to base 2

Therefore (0.68475)10 = (0.10101)2

2 0.68475 1. 3695 MSD

2 0.3695 0.7390  

2 0.7390 1.4780  

2 0.4780 0.9560  

2 0.9560 1.9120 LSD

Page 24: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 24

Signed Number Representation

There are 3 systems to represent signed numbers in binary number system:–  Signed-magnitude– 1's complement– 2's complement

Page 25: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 25

Signed-magnitude system

In signed-magnitude systems, the most significant bit represents the number's sign, while the remaining bits represent its absolute value as an unsigned binary magnitude.– If the sign bit is a 0, the number is positive.– If the sign bit is a 1, the number is negative.

Page 26: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 26

Signed-magnitude system

Page 27: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 27

1's Complement system

• A 1's complement system represents the positive numbers the same way as in the signed-magnitude system. The only difference is negative number representations.

• Let be N any positive integer number and be a negative 1's complement integer of N. If the number length is n bits, then

__

N

.)12( NN n

Page 28: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 28

Example of 1's Complement

For example in a 4-bit system, 0101 represents +5 and

1010 represents 5

1010

01011111

0101)000110000(0101000124

Page 29: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 29

1's Complement system

Page 30: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 30

2's Complement system

• A 2's complement system is similar to 1's complement system, except that there is only one representation for zero.

• Let be N any positive integer number and

be a negative 2's complement integer of N. If the number length is n bits, then

__

N

.2 NN n

Page 31: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 31

Example of 2's Complement

For example in a 4-bit system, 0101 represents +5 and

1011 represents 5

1011

010110000010124

Page 32: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 32

2's Complement system

Page 33: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 33

Addition and Subtraction in Signed and Magnitude

(a) 5+2

0101+0010

7 0111

(b) -5-2

1101+1010

-7 1111

(c) 5-2

0101+1010

3 0011

(d) -5+2

1101+0010

-3 1011

Page 34: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 34

Addition and Subtraction in 1’s Complement

(a) 5+2

0101+0010

7 0111

(b) -5-2

1010 +1101

-7 1 0111 1 1000

(c) 5-2

0101 +1101

3 1 0010 1 0011

(d) -5+2

1010 +0010

-3 1100

Page 35: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 35

Addition and Subtraction in2’s Complement

(a) 5+2

0101+0010

7 0111

(b) -5-2

1011 +1110

-7 1 1001

(c) 5-2

0101 +1110

3 1 0011

(d) -5+2

1011 +0010

-3 1101

Page 36: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 36

Overflow Conditions

Carry-in carry-out 0111 1000 5 0101 -5 1011 +3 +0011 -4 +1100 -8 1000 7 10111

Carry-in = carry-out 0000 1110 +5 0101 -2 1110 +2 +0010 -6 +1010 7 0111 -8 11000

Page 37: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 37

Addition and Subtraction inHexadecimal System

(9F1B)16 -(4A36)16 : 16 9F1B

- 4A36 54E5

(9F1B)16 +(4A36)16 : 1 1 9F1B + 4A36

E951

Addition

Subtraction

Page 38: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 38

Codes

• Decimal codes

• Gray code

• Error detection code

• ASCII code

Page 39: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 39

Decimal codes

Decimal Digit BCD Excess-3 2421

8421

0 0000 0011 0000

1 0001 0100 0001

2 0010 0101 0010

3 0011 0110 0011

4 0100 0111 0100

5 0101 1000 1011

6 0110 1001 1100

7 0111 1010 1101

8 1000 1011 1110

9 1001 1100 1111

Page 40: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 40

Gray CodeDecimal Equivalent Binary Code 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

8 1000 1100

9 1001 1101

10 1010 1111

11 1011 1110

12 1100 1010

13 1101 1011

14 1110 1001

15 1111 1000

Page 41: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 41

Error detection code Parity Bit (odd) Message

1 0000

0 0001

0 0010

1 0011

0 0100

1 0101

1 0110

0 0111

0 1000

1 1001

1 1010

0 1011

1 1100

0 1101

0 1110

1 1111

Page 42: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 42

Error detection code Parity Bit (even) Message

0 0000

1 0001

1 0010

0 0011

1 0100

0 0101

0 0110

1 0111

1 1000

0 1001

0 1010

1 1011

0 1100

1 1101

1 1110

0 1111

Page 43: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 43

ASCII Code

• ASCII: American Standard Code for Information Interchange.

• Used to represent characters and textual information• Each character is represented with 1 byte

– upper and lower case letters: a..z and A..Z– decimal digits -- 0,1,…,9– punctuation characters -- ; , . : – special characters --$ & @ / { – control characters -- carriage return (CR) , line feed (LF),

beep

Page 44: NUMBER SYSTEMS  AND  CODES

CS 3402--Digital Logic Number Systems and Codes 44

Assignment 1

Page 74– 1.1: Only A+B and AB (a), (c), (f), and (g)– 1.2: Only A+B and AB (a), (c)– 1.3: Only A+B and AB (a), (c)– 1.4: (a), (c), (e)– 1.5: (a), (c), (e)– 1.6: (a), (e)– 1.7: (a), (b)– 1.8: (a), (b)– 1.10: (a), (c)– 1.11: (a), (c)– 1.12: (a), (c)– 1.13: (a), (b)