Download Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Section 2.6
Representation of
numbers
Decimal representation (base 10)
Given a positive integer X, the decimal
representation of X is a string of digits
from {0,1,2,3,4,5,6,7,8,9} that looks like
where
d d ,..., d d d
n
n 1
2 1 0
n
X   d i10i  d n10 n  d n 110 n 1  ...  d 210 2  d1101  d 0100
i 0
Ex: (2037)ten = 2×103 + 0×102 + 3×101 + 7×100
Prove: Multiplying a decimal number by 10 shifts the
digits one place to the left and places a “0” on the end.
Base two representation
Given a positive integer X, the binary
representation of X is a string of digits
from {0,1} that looks like
where
b b ,..., b b b
n n 1
2 1 0
n
X   b i 2i  bn 2 n  bn 1 2 n 1  ...  b2 2 2  b1 21  b0 20
i 0
Ex: (10111)two = 1×24 + 0×23 + 1×22 + 1×21 + 1×20
Let x=(10101)two
What decimal number represents x?
What is the binary representation for 2x?
Multiplying Binary Numbers by 2
Note that the binary numeral for 2x is
formed by shifting the x bits to the left and
placing a “0”on the right.
For 2x+1 we place a “1” on the right after
doing the shift.
The binary representation for 14 is 1110. What
is the binary representation for 29?
By the division theorem, 29=2*14+1, so…
Every natural number has a binary
representation.
Proof by Induction:
Let P(n) be the statement “n has a binary
representation”.
Check that P(n) is true for the base case. Note
that P(0) and P(1) holds.
Now suppose that P(2), P(3), …., P(m-1) have
been check for some m >1.
Prove that P(m) holds.
 By the division theorem, there are integers q and r such
that (1) m=2q+r and (2) r is from the set {0,1}.
Since q<m, P(q) has been checked, so we know q has a
k
binary representation: bk bk 1 ,..., b2b1b0 . So,
i
q   bi 2 .
i 0
k
k
i 0
i 0
i
i 1

2

(
b
2
)

r

(
b
2
Now, m=2q+r
i
 i )r
So the binary representation for m is
bk bk 1 ,..., b2b1b0 r.
The proof tells us how to write a
number in base 2:
Input a natural number n
While n>0, do the following:
Divide n by 2 and get a quotient q and
remainder r.
Write r as the next (right-to-left) digit.
Replace the value of n and q, and repeat.
Write the base 10 number 65 in base 2.








Begin with n=35.
35/2 = 17 with remainder 1, so write 1, and let n=17.
17/2=8 with remainder 1, so write 1, and let n=8.
8/2=4 with remainder 0, so write 0, and let n=4.
4/2=2 with remainder 0, so write 0,and let n=2.
2/2=1 with remainder 0, so write 0,and let n=1
½=0 with remainder 1, so write 1, and let n=0.
Since n=0, quit.
The numeral is then 100011.
Examples of other “place value systems”
(2037)ten = 2×103 + 0×102 + 3×101 + 7×100
(231)eight = 2×82 + 3×81 + 1×80
(403)five = 4×52 + 0×51 + 3×50
Practice
(5401)six = (_____________)ten
Converting to other bases
Example. (2037)ten = (____________)eight
 2037 ÷ 8
 254 ÷ 8
 31 ÷ 8
3÷8
Quo 254
Quo 31
Quo 3
Quo 0
Rem 5
Rem 6
Rem 7
Rem 3
Answer. (2037)ten = (3765)eight
Practice
(1203)ten = (_____________)five
Practice
(1203)ten = (_____________)two
Claim. For all n  0, 10n – 1 is divisible by 3.
Before beginning the proof, let’s define
an = 10n – 1.
From this closed formula, it is easy to see that
the following recursive description is the same
thing: “a0 = 0, an = 10*an-1 + 9.”
We will prove that “an is divisible by 3” for all n 
0.
Proving these properties
Claim. For all n  0, 10n – 1 is divisible by 3.
Proof by induction. Consider the statement P(n) that states, “an is divisible
by 3.” It is easy to check the base case.
P(0) says, “0 is divisible by 3,” which is true.
Now let m be the first number for which P(m) has not yet been
checked. In particular, P(m – 1) has been checked, so we know that
“am-1 is divisible by 3.”
This means that am-1 = 3K for some integer K. From this it follows that
am = 10(am-1) + 9
= 10(3K) + 9
= 3 (10K + 3)
Since 10K + 3 is an integer, we can conclude that am is divisible by 3.
Proving properties
Claim. If S be the sum of the (base ten) digits in n,
then n – S is divisible by 3.
Proof.
We can represent n = ck10k + … + c1 101 + c0100,
and this means that S = ck + … + c1 + c0, from
which it follows that
n – S = ck(10k – 1) + … + c1 (101 – 1) + (c0 – 1)100,
Each of 10k – 1, …, 101 – 1, and 100 – 1 is
divisible by 3, so n – S is divisible by 3.
Related documents