Codes

34
Muhammad Uzair Rasheed Roll No: 2009-CPE-03 Department Of Computer Engineering UCE&T BZU Multan

Transcript of Codes

Page 1: Codes

Muhammad Uzair Rasheed

Roll No: 2009-CPE-03

Department Of Computer Engineering UCE&T BZU

Multan

Page 2: Codes

Codes

Page 3: Codes

Coding System

Coding is the process of altering the characteristics of information to make it more suitable for intended application

Page 4: Codes

CODES

Digital system codes are› BCD code› Excess-3 code› EBCDIC code› Error detection code› UNI CODE› ASCII code› Extended ASCII code› Gray code

Page 5: Codes

How do we select a coding scheme?

It should have some desirable properties

Ease of coding To increase efficiency of transmission Ease in arithmetic operations Minimum use of hardware Error detection property Ability to prevent wrong output during

transitions

Page 6: Codes

6

BCD – Binary Coded Decimal

6 3 4 9

0110 0011 0100 1001

BCD is a convention for mapping binary numbers to decimal numbers & for Decimal to binary numbers.

When the decimal numbers are represented in BCD, each decimal digit is represented by the equivalent BCD code.

Example :BCD Representation of Decimal 6349

Page 7: Codes

BCD

0-9 decimal digits need to be represented in a binary code which must contain at least four bits.› Four bits can make upto 16 different

combinations.› Only first 10 combinations are used. (0-9)

BCD is different from binary representation.› 15 in binary is 1111

Page 8: Codes

Binary-Coded Decimal (BCD)

Note: the following bit patterns are not used:

101010111100110111101111

Digit Bit pattern

0 0000

1 0001

2 0010

3 0011

4 0100

5 0101

6 0110

7 0111

8 1000

9 1001

Page 9: Codes

IF Sum Exceeds 9

Example: lets add 56 & 98 56 0101 0110+ 98 1001 1000 =154 1110 1110 Not in BCD

0110 0110 add 6

1 0101 0100

1 5 4

Page 10: Codes

10

The excess-3 code is obtained by adding 3 (0011) to the corresponding BCD equivalent binary number.

EXCESS 3 CODE

Page 11: Codes

11

EXCESS 3 CODEDecimal BCD Excess-3Number Number Number

0 0000 0011 1 0001 0100 2 0010 0101 3 0011 0110 4 0100 0111 5 0101 1000 6 0110 1001 7 0111 1010 8 1000 1011 9 1001 1100

Page 12: Codes

EBCDIC Code

Extended BCD Interchange Code 8-bit code It contains the numbers from 0 to 28-1 Developed by IBM Rarely used today IBM mainframes only

Page 13: Codes

Error Detection and Correction We need a mechanism of correcting the

errors that occur It is not always possible or may prove to

be expensive It is necessary to know if an error occurred

If an occurrence of error is known, data

may be retransmitted Data integrity is improved by encoding Encoding may be done for error correction.

Page 14: Codes

Error Detection Code

Error detection code detect errors during transmission of data from one location to another.

Error rate cannot be reduced to zero To achieve error-detection we use a

parity bit.

Page 15: Codes

Error Correction

A parity bit is an extra bit included with a message to the total number of 1’s transmitted either odd or even.

Parity bit allows us only to detect the presence of one bit error in a group of bits.

It does not enable us to exactly locate the bit that changed.

Parity bit scheme can be extended to locate the faulty bit In a block of information.

Page 16: Codes

Even parity Bit generator

Page 17: Codes

Odd parity Bit generator

Odd parity bit generator can be formed by inverting the output of the Even parity bit generator.

Page 18: Codes

Thank You

Page 19: Codes

Muhammad Saddam

Roll No: 2009-CPE-01

Department Of Computer Engineering UCE&T BZU Multan

Page 20: Codes

Gray Code Gray coding is an important code and is

used for its speed, it is also relatively free from errors.

Gray coding avoids this since only one bit changes between subsequent numbers.

In pure binary coding then counting from 7 (0111) to 8 (1000) requires 4 bits to be changed simultaneously.

Gray code is used to represent the digital data when it is converted from analog data.

Page 21: Codes

The Gray Code

Decimal

Binary

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

Decimal

Binary

Gray Code

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 22: Codes

Convert a Gray coded number to a straight binary number

Scan the Gray code word from left to right All the bits of the binary code are the same as

those of the Gray code until the first 1 is encountered, including the first 1

1’s are written until the next 1 is encountered, in which case a 0 is written.

0’s are written until the next 1 is encountered, in which case a 1 is written.

Examples Gray code : 1 1 0 1 1 0 Binary code: 1 0 0 1 0 0

Page 23: Codes

UNICODE

UNICODE is a 16-bit code for representing alphanumeric data.

Developed by a consortia(An association or a combination, as of businesses, financial institutions, or investors, for the purpose of engaging in a joint venture.)

With 16 bits, can represent 216 or 65536 different symbols.

16 bits = 2 Bytes per character. UNICODE used by Web browsers and

Java these days.

Page 24: Codes

24

• The standard binary code for representation of alphanumeric characters is ASCII

•ASCII (American Standard for Information Interchange)

•It hands not only numbers but letters and special characters

• Uses 7 bits to code 128 characters

•In ASCII, every letter, number, and punctuation symbol has a corresponding number, or ASCII code

ASCII Code

Page 25: Codes

ASCII Code

This code is a popular code used to represent information sent as character-based data. It uses 7-bits to represent:› 94 Graphic printing characters.› 34 Non-printing characters

Some non-printing characters are used for text format (e.g. BS = Backspace, CR = carriage return)

Other non-printing characters are used for record marking and flow control (e.g. STX and ETX start and end text areas).

Page 26: Codes

95 Graphic codes

000 001 010 011 100 101 110 1110000 NULL DLE 0 @ P ` p0001 SOH DC1 ! 1 A Q a q0010 STX DC2 " 2 B R b r0011 ETX DC3 # 3 C S c s0100 EDT 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 SO RS . > N ^ n ~1111 SI US / ? O _ o DEL

Page 27: Codes

33 Control codes

000 001 010 011 100 101 110 1110000 NULL DLE 0 @ P ` p0001 SOH DC1 ! 1 A Q a q0010 STX DC2 " 2 B R b r0011 ETX DC3 # 3 C S c s0100 EDT 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 SO RS . > N ^ n ~1111 SI US / ? O _ o DEL

Page 28: Codes

Alphabetic codes

000 001 010 011 100 101 110 1110000 NULL DLE 0 @ P ` p0001 SOH DC1 ! 1 A Q a q0010 STX DC2 " 2 B R b r0011 ETX DC3 # 3 C S c s0100 EDT 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 SO RS . > N ^ n ~1111 SI US / ? O _ o DEL

Page 29: Codes

Numeric codes

000 001 010 011 100 101 110 1110000 NULL DLE 0 @ P ` p0001 SOH DC1 ! 1 A Q a q0010 STX DC2 " 2 B R b r0011 ETX DC3 # 3 C S c s0100 EDT 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 SO RS . > N ^ n ~1111 SI US / ? O _ o DEL

Page 30: Codes

000 001 010 011 100 101 110 1110000 NULL DLE 0 @ P ` p0001 SOH DC1 ! 1 A Q a q0010 STX DC2 " 2 B R b r0011 ETX DC3 # 3 C S c s0100 EDT 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 SO RS . > N ^ n ~1111 SI US / ? O _ o DEL

Punctuation, etc.

Page 31: Codes

ASCII conversion example

Let us convert You & I, to decimal, hex and binary using the ASCII code table :› Y: 8910 5916 10110012

› o: 11110 6F16 11011112

› u: 11710 7516 11101012

› Space: 3210 2016 01000002

› &: 3810 2616 01001102

› Space: 3210 2016 01000002

› I: 7310 4916 10010012

› ,: 4410 2C16 01011002

Page 32: Codes

Extended ASCII

The term extended ASCII (or high ASCII) describes eight-bit or larger character encodings that include the standard seven-bit ASCII characters as well as others.

Page 33: Codes

Extended ASCII

Page 34: Codes

Thank You