Figure 3-2: Arithmetic with Binary Numbers, Continued Exam ples Binary Decimal 1000 8 +1 十 =1001 =9 =1010 10 =1011 十 十 100 12
11 Figure 3-2: Arithmetic with Binary Numbers, Continued Binary Decimal 1000 8 +1 +1 =1001 =9 +1 +1 =1010 =10 +1 +1 =1011 =11 +1 +1 =1100 =12 Examples
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 12
12 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 13
13 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 14
14 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? 15
15 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?