D ATA REPRESENTATION, BINARY SYSTEM, B IT, B YTE, ASCII C ODE Chapter 4 Lecturer In Charge: Manesh T 1
D ATA R EPRESENTATION Data Representation refers to how Computers store lots of different types of information: numbers text graphics of many varieties (stills, video, animation) sound 2
M EMORY S TRUCTURE IN C OMPUTER Memory consists of bits (0 or 1) – a single bit can represent two pieces of information bytes (=8 bits) – a single byte can represent 256 = 2x2x2x2x2x2x2x2 = 2 8 pieces of information words (=2,4, or 8 bytes) – a 2 byte word can represent pieces of information (approximately 65 thousand). Byte addressable - each byte has its own address. 3
B INARY SYSTEM 4
C LASSIFICATIONS 5
S TORAGE U NITS 6
N UMBER S YSTEMS Binary (2)Decimal (10)Octal (8) Hexadecimal (16) 0000' ' ' ' ' ' '66'6' 0111' '8 1001'9 1010'10 A 1011'11 B 1100'12 C 1101'13 D 1110'14 E 1111'15 F 7
C ONVERSION A MONG B ASES The possibilities: Hexadecimal DecimalOctal Binary pp
Q UICK E XAMPLE = = 31 8 = Base 9
D ECIMAL TO D ECIMAL ( JUST FOR FUN ) Hexadecimal DecimalOctal Binary Next slide… 10
=>5 x 10 0 = 5 2 x 10 1 = 20 1 x 10 2 = Base Weight 11
B INARY TO D ECIMAL Hexadecimal DecimalOctal Binary 12
B INARY TO D ECIMAL Technique Multiply each bit by 2 n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results 13
E XAMPLE => 1 x 2 0 = 1 1 x 2 1 = 2 0 x 2 2 = 0 1 x 2 3 = 8 0 x 2 4 = 0 1 x 2 5 = Bit “0” 14
O CTAL TO D ECIMAL Hexadecimal DecimalOctal Binary 15
O CTAL TO D ECIMAL Technique Multiply each bit by 8 n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results 16
E XAMPLE => 4 x 8 0 = 4 2 x 8 1 = 16 7 x 8 2 =
H EXADECIMAL TO D ECIMAL Hexadecimal DecimalOctal Binary 18
H EXADECIMAL TO D ECIMAL Technique Multiply each bit by 16 n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results 19
E XAMPLE ABC 16 =>C x 16 0 = 12 x 1 = 12 B x 16 1 = 11 x 16 = 176 A x 16 2 = 10 x 256 =
D ECIMAL TO B INARY Hexadecimal DecimalOctal Binary 21
D ECIMAL TO B INARY Technique Divide by two, keep track of the remainder First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 Etc. 22
E XAMPLE = ? =
O CTAL TO B INARY Hexadecimal DecimalOctal Binary 24
O CTAL TO B INARY Technique Convert each octal digit to a 3-bit equivalent binary representation 25
E XAMPLE = ? =
H EXADECIMAL TO B INARY Hexadecimal DecimalOctal Binary 27
H EXADECIMAL TO B INARY Technique Convert each hexadecimal digit to a 4-bit equivalent binary representation 28
E XAMPLE 10AF 16 = ? A F AF 16 =
C LASS WORK Convert Decimal to Binary 1. (421) 10 = ( ) 2 2. (1025) 10 = ( ) 2 3. (368) 10 = ( ) 2 4. (687) 10 = ( ) 2 5. (625) 10 = ( ) 2 6. (752) 10 = ( ) 2 30
C LASS WORK Convert Binary to Hexadecimal 1. ( ) 2 = ( ) ( ) 2 = ( ) ( ) 2 = ( ) ( ) 2 = ( ) ( ) 2 = ( ) ( ) 2 = ( ) 16 31
C LASS WORK Convert Hexadecimal to Binary 1. (AF1) 16 = ( ) 2 2. (924) 16 = ( ) 2 3. (3569) 16 = ( ) 2 4. (4526) 16 = ( ) 2 5. (6548) 16 = ( ) 2 6. (1334) 16 = ( ) 2 32
ASCII The most common code used in computers is ASCII (American Standard Code for Information Interchange). ASCII provides codes for letters, digits, punctuation marks, and other special characters. The ASCII code for A is 65 =
ASCII C ODES Sp!“#$%&‘()*+, / :; JKLMNOPQRSTUVW XYZ[\]^_`abcde fghijklmnopqrs tuvw xyz{|}~
ASCII REPRESENTATION OF T EXT Since the ASCII codes for ART are 65, 82, and 84, the three bytes representing the word ART would be Nearly all software which deals with text (Notepad, WordPerfect, Word) use the ASCII codes to represent such text, though they may use proprietary codes to deal with fonts, etc. 35
C HAPTER 4 E ND 36