29
CODES CODES ICS 30/CS 30 ICS 30/CS 30

Codes

Embed Size (px)

Citation preview

Page 1: Codes

CODESCODES

ICS 30/CS 30ICS 30/CS 30

Page 2: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BINARY CODESBINARY CODES

Electronic digital systems use signals that have Electronic digital systems use signals that have two distinct values and circuit elements that have two distinct values and circuit elements that have two stable states.two stable states.

A binary number of A binary number of nn digits, for example, may be digits, for example, may be represented by represented by nn binary circuit elements, each binary circuit elements, each having an output signal equivalent to a 0 or a 1.having an output signal equivalent to a 0 or a 1.

Any discrete element of info. Distinct among a Any discrete element of info. Distinct among a group of quantities can be represented by a binary group of quantities can be represented by a binary code.code.– Ex. Red is one distinct color of the spectrum.Ex. Red is one distinct color of the spectrum.

Page 3: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

A A bitbit, by defn., is a binary digit., by defn., is a binary digit. Binary codes for decimal digits require a Binary codes for decimal digits require a

minimum of four bits. minimum of four bits. Numerous different codes can be obtained Numerous different codes can be obtained

by arranging four or more bits in ten distinct by arranging four or more bits in ten distinct possible combinations.possible combinations.

BINARY CODESBINARY CODES

Page 4: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

Decimaldigit

(BCD)8421

Excess-3 84-2-1 2421 (Biquinary)5043210

0 0000 0011 0000 0000 0100001

1 0001 0100 0111 0001 0100010

2 0010 0101 0110 0010 0100100

3 0011 0110 0101 0011 0101000

4 0100 0111 0100 0100 0110000

5 0101 1000 1011 1011 1000001

6 0110 1001 1010 1100 1000010

7 0111 1010 1001 1101 1000100

8 1000 1011 1000 1110 1001000

9 1001 1100 1111 1111 1010000

Bin

ary

Cod

es fo

r th

e de

cim

al d

igits

Page 5: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

It is possible to assign weights to the binary It is possible to assign weights to the binary bits according to their positions.bits according to their positions.– BCD code, 84-2-1, 2421, 5043210BCD code, 84-2-1, 2421, 5043210– Weighted codesWeighted codes

Numbers are represented in digital Numbers are represented in digital computers either in binary or in decimal computers either in binary or in decimal through a binary code.through a binary code.

BINARY CODESBINARY CODES

Page 6: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

The input decimal numbers are stored internally in The input decimal numbers are stored internally in the computer by means of a decimal code.the computer by means of a decimal code.

Each decimal digit requires at least four binary Each decimal digit requires at least four binary storage elements. The decimal numbers are storage elements. The decimal numbers are converted to binary when arithmetic operations are converted to binary when arithmetic operations are done internally w/ numbers represented in binary.done internally w/ numbers represented in binary.

It is also possible to perform arithmetic operations It is also possible to perform arithmetic operations directly in decimal w/ all numbers left in a coded directly in decimal w/ all numbers left in a coded form throughout.form throughout.

BINARY CODESBINARY CODES

Page 7: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

Example: (395)Example: (395)10 10 when converted to binary, when converted to binary, is equal to 110001011 and consists of nine is equal to 110001011 and consists of nine binary digits.binary digits.

The same number, when represented The same number, when represented internally in the BCD code, occupies four internally in the BCD code, occupies four bits for each decimal digit, for a total of 12 bits for each decimal digit, for a total of 12 bits: 001110010101. bits: 001110010101.

The first 4 bits represent a 3, the next 4 a 9, The first 4 bits represent a 3, the next 4 a 9, and the last 4 a 5.and the last 4 a 5.

BINARY CODESBINARY CODES

Page 8: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

It is very important to understand the difference It is very important to understand the difference between between conversionconversion of a decimal number to binary of a decimal number to binary and the binary and the binary codingcoding of a decimal number. of a decimal number.

In each case the final result is a series of bits.In each case the final result is a series of bits. The bits obtained from conversion are binary The bits obtained from conversion are binary

digits.digits. The bits obtained from coding are combinations of The bits obtained from coding are combinations of

1’s and 0’s arranged according to the rules of the 1’s and 0’s arranged according to the rules of the code used.code used.

BINARY CODESBINARY CODES

Page 9: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BINARY CODESBINARY CODES

The BCD code, for example, has been chosen to be both a code and a direct binary conversion, as long as the decimal numbers are integers from 0 to 9.For numbers greater than 9, the conversion and For numbers greater than 9, the conversion and the coding are completely different.the coding are completely different.Example: The binary conversion of decimal 13 is Example: The binary conversion of decimal 13 is 1101; the coding of decimal 13 with BCD is 1101; the coding of decimal 13 with BCD is 00010011.00010011.

Page 10: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BCD code is the most natural to use and is indeed BCD code is the most natural to use and is indeed the one most commonly encounteredthe one most commonly encountered

Excess-3, 2421, and the 84-2-1 are self Excess-3, 2421, and the 84-2-1 are self complementary codes, that is, the 9’s complement complementary codes, that is, the 9’s complement of the decimal number is easily obtained by of the decimal number is easily obtained by changing 1’s to 0’s and 0’s to 1’s.changing 1’s to 0’s and 0’s to 1’s.

Example: (395)Example: (395)1010 is represented in the 2421 code is represented in the 2421 code by 001111111011. Its 9’s complement 604 is by 001111111011. Its 9’s complement 604 is represented by 110000000100, which is easily represented by 110000000100, which is easily obtained from the replacement of 1’s by 0’s and obtained from the replacement of 1’s by 0’s and 0’s by 1’s.0’s by 1’s.

BINARY CODESBINARY CODES

Page 11: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

The biquinary code is an example of a seven-bit The biquinary code is an example of a seven-bit code w/ error-detection properties.code w/ error-detection properties.

Each decimal digit consists of five 0’s and two 1’s Each decimal digit consists of five 0’s and two 1’s placed in the corresponding weighted columns.placed in the corresponding weighted columns.

The error-detection property of this code may be The error-detection property of this code may be understood if one realizes that digital systems understood if one realizes that digital systems represent binary 1 by one distinct signal and represent binary 1 by one distinct signal and binary 0 by a second distinct signal.binary 0 by a second distinct signal.

During transmission of signals from one location to During transmission of signals from one location to another, an error may occur.another, an error may occur.

BINARY CODESBINARY CODES

Page 12: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BINARY CODESBINARY CODES

One or more bits may change value.One or more bits may change value. A circuit in the receiving side can detect the A circuit in the receiving side can detect the

presence of more (or less) than two 1’s and, presence of more (or less) than two 1’s and, if the received combination of bits does not if the received combination of bits does not agree with the allowable combination, an agree with the allowable combination, an error is detected.error is detected.

Page 13: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BINARY CODESBINARY CODES

Error-Detection CodesError-Detection Codes– Binary information, be it pulse-modulated signals or Binary information, be it pulse-modulated signals or

digital computer input or output, may be transmitted digital computer input or output, may be transmitted through some form of communication medium such as through some form of communication medium such as wires or radio waves.wires or radio waves.

– Any external noise introduced into a physical Any external noise introduced into a physical communication medium changes bit values from 0 to 1 communication medium changes bit values from 0 to 1 or vice versa.or vice versa.

– An error-detection code can be used to detect errors An error-detection code can be used to detect errors during transmission.during transmission.

– The detected error cannot be corrected, but its presence The detected error cannot be corrected, but its presence is indicated.is indicated.

Page 14: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BINARY CODESBINARY CODES

A A parityparity bit is an extra bit included w/ a message bit is an extra bit included w/ a message to make the total number of 1’s either odd or even.to make the total number of 1’s either odd or even.

During transfer of info. from one location to During transfer of info. from one location to another, the parity bit is handled as follows: In the another, the parity bit is handled as follows: In the sending end, the message is applied to a “parity-sending end, the message is applied to a “parity-generation” network where the required P bit is generation” network where the required P bit is generated.generated.

The message, including the parity bit, is The message, including the parity bit, is transferred to its destination.transferred to its destination.

Page 15: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BINARY CODESBINARY CODES(a) Message P (odd) (b) Message P (even)

0000 1 0000 0

0001 0 0001 1

0010 0 0010 1

0011 1 0011 0

0100 0 0100 1

0101 1 0101 0

0110 1 0110 0

0111 0 0111 1

1000 0 1000 1

PA

RIT

Y-B

IT G

EN

ER

AT

ION

Page 16: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BINARY CODESBINARY CODES1001 1 1001 0

1010 1 1010 0

1011 0 1011 1

1100 1 1100 0

1101 0 1101 1

1110 0 1110 1

1111 1 1111 0

PA

RIT

Y-B

IT G

EN

ER

AT

ION

Page 17: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

In the receiving end, all incoming bits are In the receiving end, all incoming bits are applied to a “parity-check” network to check applied to a “parity-check” network to check the proper parity adopted.the proper parity adopted.

An error is detected if the checked parity An error is detected if the checked parity does not correspond to the adopted one.does not correspond to the adopted one.

The parity method detects the presence of The parity method detects the presence of one, three, or any odd combination of errors.one, three, or any odd combination of errors.

An even combination is undetectable.An even combination is undetectable.

BINARY CODESBINARY CODES

Page 18: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

Reflected Code(also known as the Reflected Code(also known as the GrayGray code) code)Digital systems can be designed to process Digital systems can be designed to process

data in discrete form only. Many physical systems data in discrete form only. Many physical systems supply continuous output data. These data must supply continuous output data. These data must be converted into digital or discrete form before be converted into digital or discrete form before they are applied to a digital system.they are applied to a digital system.

Advantage:Advantage:A number in the reflected code changes by A number in the reflected code changes by

only one bit as it proceeds from one number to the only one bit as it proceeds from one number to the next.next.

BINARY CODESBINARY CODES

Page 19: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BINARY CODESBINARY CODESReflected Code Decimal Equivalent

0000 0

0001 1

0011 2

0010 3

0110 4

0111 5

0101 6

0100 7

1100 8

Page 20: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

BINARY CODESBINARY CODES1101 9

1111 10

1110 11

1010 12

1011 13

1001 14

1000 15

Page 21: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

Alphanumeric CodesAlphanumeric Codes

Many applications of digital computers Many applications of digital computers require the handling of data that consist not only of require the handling of data that consist not only of numbers, but also of letters. numbers, but also of letters.

An alphanumeric code is a binary code of a An alphanumeric code is a binary code of a group of elements consisting of the 10 decimal group of elements consisting of the 10 decimal digits, the 26 letters of the alphabet, and a certain digits, the 26 letters of the alphabet, and a certain number of special symbols such as $.number of special symbols such as $.

BINARY CODESBINARY CODES

Page 22: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

The total number of elements in an alphanumeric The total number of elements in an alphanumeric group is greater than 36. Therefore, it must be group is greater than 36. Therefore, it must be coded with a minimum of 6 bits (2coded with a minimum of 6 bits (266 = 64, but 2 = 64, but 255 = = 32 is insufficient). 32 is insufficient).

One possible arrangement of a 6-bit One possible arrangement of a 6-bit alphanumeric code is shown in the table under alphanumeric code is shown in the table under the name “internal code.” The need to represent the name “internal code.” The need to represent more than 64 characters gave rise to 7- and 8- more than 64 characters gave rise to 7- and 8- bit alphanumeric codes. One such code is known bit alphanumeric codes. One such code is known as ASCII. Another is known as EBCDIC. as ASCII. Another is known as EBCDIC.

BINARY CODESBINARY CODES

Page 23: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

ALPHANUMERIC CHARACTER ALPHANUMERIC CHARACTER CODESCODES

Character 6-Bit internal code

7-Bit ASCII code

8-Bit EBCDIC

code

12-Bit card code

A 010 001 100 0001 1100 0001 12,1

B 010 010 100 0010 1100 0010 12,2

C 010 011 100 0011 1100 0011 12,3

D 010 100 100 0100 1100 0100 12,4

E 010 101 100 0101 1100 0101 12,5

F 010 110 100 0110 1100 0110 12,6

G 010 111 100 0111 1100 0111 12,7

Page 24: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

ALPHANUMERIC CHARACTER ALPHANUMERIC CHARACTER CODESCODES

H 011 000 100 1000 1100 1000 12,8

I 011 001 100 1001 1100 1001 12,9

J 100 001 100 1010 1101 0001 11,1

K 100 010 100 1011 1101 0010 11,2

L 100 011 100 1100 1101 0011 11,3

M 100 100 100 1101 1101 0100 11,4

N 100 101 100 1110 1101 0101 11,5

O 100 110 100 1111 1101 0110 11,6

P 100 111 101 0000 1101 0111 11,7

Page 25: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

ALPHANUMERIC CHARACTER ALPHANUMERIC CHARACTER CODESCODES

Q 101 000 101 0001 1101 1000 11,8

R 101 001 101 0010 1101 1001 11,9

S 110 010 101 0011 1110 0010 0,2

T 110 011 101 0100 1110 0011 0,3

U 110 100 101 0101 1110 0100 0,4

V 110 101 101 0110 1110 0101 0,5

W 110 110 101 0111 1110 0110 0,6

X 110 111 101 1000 1110 0111 0,7

Y 111 000 101 1001 1110 1000 0,8

Z 111 001 101 1010 1110 1001 0,9

Page 26: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

ALPHANUMERIC CHARACTER ALPHANUMERIC CHARACTER CODESCODES

0 000 000 011 0000 1111 0000 0

1 000 001 011 0001 1111 0001 1

2 000 010 011 0010 1111 0010 2

3 000 011 011 0011 1111 0011 3

4 000 100 011 0100 1111 0100 4

5 000 101 011 0101 1111 0101 5

6 000 110 011 0110 1111 0110 6

7 000 111 011 0111 1111 0111 7

8 001 000 011 1000 1111 1000 8

9 001 001 011 1001 1111 1001 9

Page 27: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

ALPHANUMERIC CHARACTER ALPHANUMERIC CHARACTER CODESCODES

Blank 110 000 010 0000 0100 0000 No punch

. 011 011 010 1110 0100 1011 12,8,3

( 111 100 010 1000 0100 1101 12,8,5

+ 010 000 010 1011 0100 1110 12,8,6

$ 101 011 010 0100 0101 1011 11,8,3

* 101 100 010 1010 0101 1100 11,8,4

) 011 100 010 1001 0101 1101 11,8,5

- 100 000 010 1101 0110 0000 11

/ 110 001 010 1111 0110 0001 0,1

, 111 011 010 1100 0110 1011 0,8,3

= 001 011 011 1101 0111 1110 8,6

Page 28: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

When discrete info. is transferred through punch cards, When discrete info. is transferred through punch cards, the alphanumeric characters use a 12-bit binary the alphanumeric characters use a 12-bit binary code.code.

A punch card consists of 80 columns and 12 rows - in A punch card consists of 80 columns and 12 rows - in each column an alphanumeric character is each column an alphanumeric character is represented by holes punched in the appropriate represented by holes punched in the appropriate rows. A hole is sensed as a 1 and the absence of a rows. A hole is sensed as a 1 and the absence of a hole is sensed as a 0.hole is sensed as a 0.

12-BIT CARD CODE12-BIT CARD CODE

The 12 rows are marked, starting from the top, The 12 rows are marked, starting from the top, as the 12, 11, 0, 1, 2,…,9 punch. The first 3 are as the 12, 11, 0, 1, 2,…,9 punch. The first 3 are called the called the zonezone punch and the last 9 are called the punch and the last 9 are called the numericnumeric punch. punch.

Page 29: Codes

mariaramilaisidrojimenezmariaramilaisidrojimenez XUCCXUCC

Most computers translate the input code into Most computers translate the input code into an internal 6-bit code. As an example, the an internal 6-bit code. As an example, the internal code representation of the name internal code representation of the name “John Doe” is:“John Doe” is:

100001 100110 011000 100101 110000100001 100110 011000 100101 110000 J O H N blank J O H N blank

BINARY CODESBINARY CODES

010100010100 100110 010101100110 010101

D O E