Figure 3-3: Binary Encoding for Alternatives Encoding Alternatives (Product number, region, gender, etc (N bits can represent 2N Alternatives) Number of Alternatives Num ber of bits That Can be Encoded In Field (n with n bits 2348 248 222 16(24) 256(2 16 65,536(216) Each added bit doubles the number of alternatives that can be represented
11 Figure 3-3: Binary Encoding for Alternatives Encoding Alternatives (Product number, region, gender, etc.) (N bits can represent 2N Alternatives) Number of Bits In Field (N) 1 2 3 4 8 16 … Number of Alternatives That Can be Encoded with N bits 2 (21 ) 4 (22 ) 8 (23 ) 16 (24 ) 256 (28 ) 65,536 (216) … Each added bit doubles the number of alternatives that can be represented
Figure 3-3: Binary Encoding for Alternatives Bits Alternatives Examples 21=2 Male =o female 1 2 22=4 Spring=00, Summer=01 Autumn = 10. Winter =11 8 28=256 Keyboard characters for U.S keyboards. Space=00000000, etc ASCll code actually uses 7 bits 12
12 Figure 3-3: Binary Encoding for Alternatives Bits Alternatives Examples 1 2 1=2 Male = 0, Female = 1 2 2 2=4 Spring = 00, Summer = 01, Autumn = 10, Winter = 11 8 2 8=256 Keyboard characters for U.S. keyboards. Space=00000000, etc. ASCII code actually uses 7 bits
Powers of 2 Bits Alternatives Each additional bit doubles the number of possibilities 2345 248 Start with one you know and double or halve until 16 you have what you need 32 E.g., if you know 8 is 256, 64 10 must be 4 times as 128 large or 1,024 678 256 Memorize for 1. 4.8. and 10 1.024 16 bits 16 65536 13
13 Powers of 2 Bits Alternatives 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 10 1,024 16 65,536 Each additional bit doubles the number of possibilities Start with one you know and double or halve until you have what you need E.g., if you know 8 is 256, 10 must be 4 times as large or 1,024. Memorize for 1, 4, 8, and 16 bits
Figure 3-3: Binary Encoding for Alternatives Quiz How many flavors of ice cream can you represent in half a byte of storage? How many bits do you need to represent 64 flavors of ice cream? How many bits do you need to represent 6 sales districts? 14
14 Figure 3-3: Binary Encoding for Alternatives • Quiz – How many flavors of ice cream can you represent in half a byte of storage? – How many bits do you need to represent 64 flavors of ice cream? – How many bits do you need to represent 6 sales districts?
Figure 3-4: AsCll and Extended Ascll ASCll Code to Represent Text ASCll is the traditional binary code to represent text data Seven bits per character 2(128 characters possible Sufficient for all keyboard characters(including shifted values Capital letters(a is 1000001) Lowercase letters(a is 1100001) Each character is stored in a byte The 8tn bit in a byte normally is not used 15
15 Figure 3-4: ASCII and Extended ASCII • ASCII Code to Represent Text – ASCII is the traditional binary code to represent text data – Seven bits per character • 2 7 (128) characters possible – Sufficient for all keyboard characters (including shifted values) • Capital letters (A is 1000001) • Lowercase letters (a is 1100001) – Each character is stored in a byte • The 8th bit in a byte normally is not used