19
Introduction to Computer Engineering WEEK-6 CODING SYSTEMS Assoc. Prof. Dr. Ahmet Turan ÖZCERİT

Assoc. Prof. Dr. Ahmet Turan ÖZCERİT. The necessity and advantages of coding The variety of coding systems You will learn: 2

Embed Size (px)

Citation preview

Page 1: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

Introduction to Computer Engineering

WEEK-6CODING SYSTEMS

Assoc. Prof. Dr. Ahmet Turan ÖZCERİT

Page 2: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

2

The necessity and advantages of coding

The variety of coding systems

CODING SYSTEMS

You will learn:

Page 3: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

Fundamentals of Coding Systems

He/She can justify the need of coding

3

Coding can be defined as the integrity of strict rules between two clusters

In other words, representing any member of a cluster by a code

The advantage of coding

The simplicity of arithmetic operations

Helps to discover errors

Helps to recover from errors

Better performance for memory operations

Better understanding of data operations

Page 4: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

Fundamentals of Coding Systems

He/She can justify the need of coding

4

Numeric Codes

1,2,3,4,5,6….

Examples: BCD, 8 4 -2 -1, 2 4 2 1, +3Code, Gray and Parity

Alphanumeric Codes

1,2,3,A,B,C,+,%,&,/, (, ) ……

Examples: ASCII, Unicode

Page 5: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

Decimal to BCD Conversion

He/She can justify the need of coding

5

BCD Coding : Binary Coded Decimal

The decimal numbers are represented as 4-bit binary numbers

Digit BCD Code

0 0000

1 0001

2 0010

…. …..

7 0111

8 1000

9 1001

Examples BCD Code

10 0001 0000

23 0010 0011

122 0001 0010 0010

87 1000 0111

234 0010 0011 0100

897 1000 1001 0111

100 0001 0000 0000

Page 6: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

BCD to Decimal Conversion

He/She can justify the need of coding

6

Example-1: Convert (1001 0011 0110)BCD into decimal

1001 -> 9, 0011-> 3, 0110-> 6

Example-2: Convert (0001 1000 0101 0100)BCD into decimal

0001 -> 1, 1000-> 8, 0101-> 5, 0100->4

Page 7: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

8 4 -2 -1 Coding (self complementary code)

He/She can justify the need of coding

7

8 4 -2 -1 23 22 -21 -20

Decimal 8 4 -2 -1 code

0 0000

1 0111

2 0110

3 0101

4 0100

5 1011

6 1010

7 1001

8 1000

9 1111

ExamplesDecimal

8 4 -2 -1code

275 0110 1001 1011

23 0110 0101

122 0111 0110 0110

897 1000 1111 1001

Page 8: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

2 4 2 1 Coding(self complementary code)

He/She can justify the need of coding

8

Decimal 2 4 2 1 code

0 0000

1 0001

2 0010

3 0011

4 0100

5 1011

6 1100

7 1101

8 1110

9 1111

ExamplesDecimal

2 4 2 1 code

275 0110 1001 1011

23 0110 0101

122 0111 0110 0110

897 1000 1111 1001

Page 9: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

+3 Code (self complementary code)

He/She can justify the need of coding

9

The primary advantage of +3 coding over non-biased coding is that a decimal number can be nines' complemented (for subtraction) as easily as a binary number can be ones' complemented; just invert all bits. In addition, when the sum of two +3 digits is greater than 9, the carry bit of a four bit adder will be set high. This works because, when adding two numbers that are greater than or equal to zero, an "excess" value of six results in the sum. Since a four bit integer can only hold values 0 to 15, an excess of six means that any sum over nine will overflow.

https://www.youtube.com/watch?v=MXGZ4wXM7_M

0: 00111: 01002: 01013: 01104: 01115: 10006: 10017: 10108: 10119: 1100

Page 10: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

Gray Code

He/She can justify the need of coding

10

Gray coding has no radix weight

Gray code cannot be used in arithmetic

operations

It reduces error in control signals since

it is based on columns

Gray code can be converted easily into

binary and vice versa

Page 11: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

Converting Binary code into Gray

He/She can justify the need of coding

11

Page 12: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

Converting Gray code into Binary

He/She can justify the need of coding

12

Page 13: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

Gray code use

He/She can justify the need of coding

13

Page 14: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

Gray code use

He/She can justify the need of coding

14

0 0

1

0 0 00 1

0 0

1

1

1 0 1

1 1 0 1 1 1

1 0 0

sensors

Binary coded: 111 110 000

0 0

0

1 1 10 1

0 0

0

1

1 0 1

0 1 1 1 0 0

1 1 0

mis-aligned sensors

1 0

1

1 1 10 0

0 1

0

0

0 1 0

0 0 1 0 1 1

1 1 0

mis-aligned sensors

Gray coded: 111 101

Page 15: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

ALPHANUMERIC CODES

He/She can justify the need of coding

15

• Computers also handle textual data.• Character set frequently used:

alphabets: ‘A’ … ‘Z’, ‘a’ … ‘z’digits: ‘0’ … ‘9’special symbols: ‘$’, ‘.’, ‘@’, ‘*’, etc.non-printable: NULL, BELL, CR, etc.

• Examples– ASCII (8 bits), Unicode (8-bit, 16-bit, and 32-bit)

Page 16: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

ALPHANUMERIC CODES

He/She can justify the need of coding

16

ASCII American Standard Code for Information Interchange 7 bits, plus a parity bit for error detection Odd or even parity 8-bit extended ASCII: code pages for different languages

MSBsLSBs 000 001 010 011 100 101 110 1110000 NUL DLE SP 0 @ P ` p0001 SOH DC1 ! 1 A Q a q0010 STX DC2 “ 2 B R b r0011 ETX DC3 # 3 C S c s0100 EOT DC4 $ 4 D T d t0101 ENQ NAK % 5 E U e u0110 ACK SYN & 6 F V f v0111 BEL ETB ‘ 7 G W g w1000 BS CAN ( 8 H X h x1001 HT EM ) 9 I Y i y1010 LF SUB * : J Z j z1011 VT ESC + ; K [ k {1100 FF FS , < L \ l |1101 CR GS - = M ] m }1110 O RS . > N ^ n ~1111 SI US / ? O _ o DEL

Page 17: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

ERROR DETECTION

He/She can justify the need of coding

17

• Parity bit– Even parity: additional bit

added to make total number of 1’s even.

– Odd parity: additional bit added to make total number of 1’s odd.

• Example of odd parity on ASCII values.

Character ASCII Code0 0110000 11 0110001 0

. . . . . .9 0111001 1: 0111010 1A 1000001 1B 1000010 1

. . . . . .Z 1011010 1[ 1011011 0\ 1011100 1

Parity bits

Page 18: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

ERROR DETECTION

He/She can justify the need of coding

18

• Parity bit can detect odd number of errors but not even number of errors.– Example: Assume odd parity,

• 10011 10001 (detected)• 10011 10101 (not detected)

• Parity bits can also be applied to a block of data.

0110 10001 01011 01111 11001 10101 0 Column-wise parity

Row-wise parity

Page 19: Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2

QUESTIONS

19

?