38
Applied physics III Digital Codes by Benson Mbuya

Applied physics iii lecture3 digital_codes

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Applied physics iii lecture3 digital_codes

Applied physics III

Digital Codes

by Benson Mbuya

Page 2: Applied physics iii lecture3 digital_codes

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.

Page 3: Applied physics iii lecture3 digital_codes

Binary Coded Decimal (BCD)

Page 4: Applied physics iii lecture3 digital_codes

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

Page 5: Applied physics iii lecture3 digital_codes

Example• 709310 = ? (in BCD)

7 0 9 3

0111 0000 1001 0011

Page 6: Applied physics iii lecture3 digital_codes

BCD

Page 7: Applied physics iii lecture3 digital_codes

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

Page 8: Applied physics iii lecture3 digital_codes

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

Page 9: Applied physics iii lecture3 digital_codes

32 0011 001084 1000 010071 1011 0110

0110 10001 0110

Page 10: Applied physics iii lecture3 digital_codes

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

Page 11: Applied physics iii lecture3 digital_codes

Gray code

Page 12: Applied physics iii lecture3 digital_codes
Page 13: Applied physics iii lecture3 digital_codes

Converting Gray coded number to binary

Page 14: Applied physics iii lecture3 digital_codes
Page 15: Applied physics iii lecture3 digital_codes
Page 16: Applied physics iii lecture3 digital_codes

Example: binary to gray code

Page 17: Applied physics iii lecture3 digital_codes

Example: Gray code to Binary

Page 18: Applied physics iii lecture3 digital_codes

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

Page 19: Applied physics iii lecture3 digital_codes

The Problem• Representing text strings, such as

“Hello, world”, in a computer

Page 20: Applied physics iii lecture3 digital_codes

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

Page 21: Applied physics iii lecture3 digital_codes

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)

Page 22: Applied physics iii lecture3 digital_codes

ASCII Table

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

Page 23: Applied physics iii lecture3 digital_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

ASCII CHART

Page 24: Applied physics iii lecture3 digital_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

Most significant bit

Least significant bit

Page 25: Applied physics iii lecture3 digital_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

e.g., ‘a’ = 1100001

Page 26: Applied physics iii lecture3 digital_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: Applied physics iii lecture3 digital_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: Applied physics iii lecture3 digital_codes

“Hello, world” Example

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

Binary010010000110010101101100011011000110111100101100001000000111011101100111011100100110110001100100

Hexadecimal48656C6C6F2C207767726C64

Decimal72

1011081081114432119103114108100

Hello, world

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

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

Page 29: Applied physics iii lecture3 digital_codes

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

Page 30: Applied physics iii lecture3 digital_codes

Extended ASCII Table

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

Page 31: Applied physics iii lecture3 digital_codes

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

—Even Parity—Odd Parity

Page 32: Applied physics iii lecture3 digital_codes
Page 33: Applied physics iii lecture3 digital_codes
Page 34: Applied physics iii lecture3 digital_codes
Page 35: Applied physics iii lecture3 digital_codes

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

Page 36: Applied physics iii lecture3 digital_codes

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

Page 37: Applied physics iii lecture3 digital_codes