Section3.1notesall

advertisement
Section 3.1: Number Representation
Practice HW (not to hand in)
From Barr Text
p. 185 # 1-5
So far, we have studied historical cryptographic methods that are typically hand-based
Modern cryptographic methods are computer based methods. To have an appreciation for
these methods, we need to understand how computers communicate. In this section, we
study the types of numbers that computers typically work with.
Representation of Numbers
Ordinary numbers we see every day are represented as base 10, that is, as the sum of the
powers of 10. We illustrate how this is so in the following example.
Example 1: Write the number 12341 as a sum of the powers of 10.
Solution: We see that
12341  10000  2000  300  40  1
 10000  2  1000  3  100  4  10  1
 1  104  2  103  3  102  4  101  1  100
█
Binary Numbers are base 2 numbers are made up only of 0’s and 1’s. Computers use
these numbers to represent data internally. /Examples of binary numbers are 0 (which
represents the number 0) 100 (which represents the number 4), 1001 (which represents
the number 9), and 1011000 (which represents the number 88). We now give a formal
definition of a binary number.
Definition: A binary number bk bk 1 b2b1b0 , where bi  0 or 1 , represents the base 10
decimal number given by
bk 2k  bk 1 2k 1    b2 22  b1 21  b0 20
We illustrate this definition in the following examples.
Example 2: Find the base 10 decimal representation of the binary numbers
a. 100
b. 1011000
c. 1110001011
Solution: For part a, if we label the binary digits as 1 0 0 , we see that
b2 b1 b0
100  1  22  0  21  0  20  4  0  0  4 . For part b, if we label the binary digits as
1 0 1 1 0 0 0 , we see that
b6 b5 b4 b3 b2 b1 b0
1011000  1  26  0  25  1  24  1  23  0  22  0  21  0  20  64  16  8  88 . For part c,
if we label the binary digits as 1 1 1 0 0 0 1 0 1 1 , we see that
b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
1110001011  1  28  1  27  1  26  0  25  0  24  0  23  0  22  1  21  1  20
 512  256  128  0  0  0  8  0  2  1
 907
█
Note: To convert a decimal (base 10) number to binary, we compute the powers of 2
(starting with 20 ) that are less than the given number. Then write the number as a sum of
these powers of 2 from largest to smallest, writing a coefficient of 1 in front the power of 2
that occurs in the sum and a 0 in front of the power of 2 that does not occur. Reading off
the coefficients from left to right gives the binary representation. We illustrate this
technique in the following examples.
Example 3: Convert 77 to binary.
Solution: The powers of 2 less than 77 are 20  1 , 21  2 , 22  4 , 23  8 , 24  16 ,
25  32 , and 26  64 . We write 77 as a sum of these powers of 2 as follows.
77  64  11
 64  8  3
 64  8  2  1
 1  26  0  25  0  24  1  23  0  22  1  21  1  20
Reading the coefficients from left to right, we see that the binary representation of
77 is 1001011.
█
Example 4: Convert 320 to binary.
Solution: The powers of 2 less than 320 are 20  1 , 21  2 , 22  4 , 23  8 , 24  16 ,
25  32 , 26  64 , 27  128 , and 28  256 . We write 320 as a sum of these powers of 2 as
follows.
324  256  68
 256  64  4
 1  28  0  27  1  26  0  25  0  24  0  23  1  22  0  21  0  20
Reading the coefficients from left to right, we see that the binary representation of
77 is 101000100.
█
Approximating the Size of a Binary Number
Many times the strength of a cryptographic method is expressed in terms of the size of a
particular parameter. Many times the size of this parameter is expressed in terms on the
number of binary digits the number has. The following formula gives an estimate of the
number of binary digits is required to expressed a given base 10 decimal number.
Number of Binary Digits Estimate
b
ln( n)
ln( 2)
where
n  base 10 decimal number
b  approximat e number of binary digits in the given number
Example 5: Approximate how many binary digits are used to represent the number
430121.
Solution: Setting n = 430121, we see that
ln( 430121)
 18.7 .
ln( 2)
Hence, it number can be represented by approximately 19 binary digits.
b
The following inequality gives a bound of the size of a base 10 number given the number
of binary digits that represent it.
Base 10 Number Size Binary Bound Estimate
2b 1  n  2b , where
n  base 10 decimal number
b  approximat e number of binary digits in the given number
█
Example 6: A base 10 number is represented by a 32 bit number. Find a bound that will
estimate its size.
Solution: Setting b = 32, we see that
2321  n  232
or
231  n  232 .
Thus,
2147483648  n  4294967296 .
█
ASCII Codes for Characters
So far, we have used the MOD 26 alphabet assignment table to assign a numerical
representation to each letter. Computers normally use the ASCII (American Standard Code
for Information Interchange) table for obtaining numerical representation of characters.
Table 1: ASCII table for characters
The capital letters A-Z is represented by the numbers 65-90.
Example 7: Find the numerical Ascii table representation for the characters z, Z, “, and a
space.
Solution: A lower case z is represented by the number 122, capital Z is represented by 90,
a quotation mark “ is represented by 34, and a space by 32.
█
Example 8: Decode the following text represented by the 8-bit blocks representing Ascii
code numbers:
01001101
01001111
01000100
00110010
Solution: We convert the numbers from binary to base 10 and find the corresponding
character representation in the Ascii table.
01001101  0  27  1  26  0  25  0  24  1  23  1  22  0  21  1  20
 64  8  4  1  77  M
01001111  0  27  1  26  0  25  0  24  1  23  1  22  1  21  1  20
 64  8  4  1  79  O
01000100  0  27  1  26  0  25  0  24  0  23  1  22  0  21  0  20
 64  4  68  D
00110010  0  27  0  26  1  25  1  24  0  23  0  22  1  21  0  20
 32  16  2  50  2
█
Download