Applied physics iii lecture3 digital_codes

Preview:

DESCRIPTION

 

Citation preview

Applied physics III

Digital Codes

by Benson Mbuya

Binary Coded Decimal (BCD)• One of the most widely used

representations of numerical data is the binary coded decimal (BCD) form in which each integer of a decimal number is represented by a 4-bit binary number (see conversion table).

• It is particularly useful for the driving of display devices where a decimal output is desired. BCD usually refers to such coding in which the binary digits have their normal values, i.e., 8421. Sometimes it is written "8421 BCD" to clearly distinguish it from other binary codes such as the4221 Code, but when BCD is used without qualification, the 8421 version is assumed.

Binary Coded Decimal (BCD)

Binary-Coded Decimal (BCD)• Four bits per digit

Digit Bit pattern0 00001 00012 00103 00114 01005 01016 01107 01118 10009 1001

Note: the following bit patterns are not used:

101010111100110111101111

Example• 709310 = ? (in BCD)

7 0 9 3

0111 0000 1001 0011

BCD

BCD Addition• Multi-digit BCD numbers can be added

together23 0010 001145 0100 010168 0110 1000

23 0010 001148 0100 100071 0110 1011

• 1011 is illegal BCD number

BCD Addition• Add a 0110 (6) to an invalid BCD number• Carry added to the most significant BCD

digit

23 0010 001148 0100 100071 0110 1011

01100111 0001

32 0011 001084 1000 010071 1011 0110

0110 10001 0110

Gray Code : Minimum Change code• Gray code is also known as reflected binary code. • The reflected binary code was originally designed to prevent

spurious outputs from electromechanical switches.• Today, Gray codes are widely used to facilitate error correction in

digital communications

Gray code

Converting Gray coded number to binary

Example: binary to gray code

Example: Gray code to Binary

Alphanumeric Codes• Represent numbers and alphabetic

characters. —Also represent other characters such as

symbols and various instructions necessary for conveying information.

• The ASCII is the most common alphanumeric code.—ASCII = American Standard Code for

Information Interchange

The Problem• Representing text strings, such as

“Hello, world”, in a computer

Codes and Characters• Each character is coded as a byte• Most common coding system is ASCII

(Pronounced ass-key)• ASCII = American National Standard Code

for Information Interchange• Defined in ANSI document X3.4-1977

ASCII Features• 7-bit code• 8th bit is unused (or used for a parity bit)• 27 = 128 codes• Two general types of codes:

—95 are “Graphic” codes (displayable on a console)

—33 are “Control” codes (control features of the console or communications channel)

ASCII Table

http://ascii-table.com/img/table.gif

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

ASCII CHART

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

Most significant bit

Least significant bit

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

e.g., ‘a’ = 1100001

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

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

“Hello, world” Example

============

Binary010010000110010101101100011011000110111100101100001000000111011101100111011100100110110001100100

Hexadecimal48656C6C6F2C207767726C64

Decimal72

1011081081114432119103114108100

Hello, world

============

============

Extended ASCII• There are an additional 128 characters

that were adopted by IBM for use in their PCs. It’s popular and is used in applications other than PCs unofficial standard.—The extended ASCII characters are

represented by an 8-bit code series from 80h-FFh

Extended ASCII Table

http://ascii-table.com/img/table-pc.gif

Error Detection• Digital Systems are very Reliable• Errors during storage or transmission• Parity Bit

—Even Parity—Odd Parity

Odd Parity Error Detection• Original data 10011010• With Odd Parity 110011010• 1-bit error 110111010• Number of 1s even indicates 1-bit error• 2-bit error 110110010• Number of 1s odd no error indicated• 3-bit error 100110010• Number of 1s even indicates error

BCD Addition

• Try these:ex: Add the following numbers

(a) 0011+0100(b) 00100011 + 00010101(c) 10000110 + 00010011(d) 010001010000 + 010000010111(e) 1001 + 0100(f) 1001 + 1001(g) 00010110 + 00010101(h) 01100111 + 01010011

Recommended