Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
MAT1830
thousands
4
4062
4062
=
=
4 1000
4 103
+
+
hundreds
0
0 100
0 102
+
+
tens
6
ones
2
6 10
6 10
+
+
21
2 100
3.2
Converting base
10
Notice that the digits are obtained, in reverse order, by repeatedly dividing by 10
and discarding the remainders:
1937 divided by 10 is 193, remainder 7.
193 divided by 10 is 19, remainder 3.
19 divided by 10 is 1, remainder 9.
1 divided by 10 is 0, remainder 1.
Thus the remainders, in reverse order, are
1,9,3,7.
3.1
Example: 1101
Base 2 notation
First digit = 1.
Multiplied by 2, plus 2nd dig
Multiplied by 2, plus 3rd dig
Multiplied by 2, plus 4th digi
On an n-digit number, th
volves n 1 multiplications
25 s
32s
0
24 s
16s
0
23 s
8s
1
22 s
4s
1
21 s
2s
0
20 s
1s
1
1 divided by 10 is 0, remainder 1.
Thus the remainders, in reverse order, are
1,9,3,7.
3.1
Base 2 notation
3.2
digit.
..
.
Add the last digit.
Example: 1101
First digit = 1.
Multiplied by 2, plus 2nd digit =
Multiplied by 2, plus 3rd digit =
Multiplied by 2, plus 4th digit =
On an n-digit number, this
volves n 1 multiplications by
additions. It is sometimes call
method, and is more efficient tha
well known method summing
3.3
Summing powers o
1 24 + 0 23 + 0 22 + 1 2
(1010111)2 = 1 26 + 0 25 + 1 24 + 0 23 + 1 22 + 1 21 + 1 20
(1010111)2 = 1 64 + 0 32 + 1 16 + 0 8 + 1 4 + 1 2 + 1 1
(1010111)2 = 87
The base 3 numeral can be found similarly by repeatedly dividing by 3 and writing
down the remainders in reverse order.
+ 9 102 + 3 101 + 7.
2 notation
3.2
by repeatedly dividing by 10
g the remainders:
d by 10 is 193, remainder 7.
by 10 is 19, remainder 3.
by 10 is 1, remainder 9.
y 10 is 0, remainder 1.
mainders, in reverse order, are
2 notation
Example: 1101
First digit = 1.
Multiplied by 2, plus 2nd digit = 2 + 1 = 3.
Multiplied by 2, plus 3rd digit = 6 + 0 = 6.
Multiplied by 2, plus 4th digit = 12 + 1 = 13
On an n-digit number, this method involves n 1 multiplications by 2 and n 1
additions. It is sometimes called Horners
method, and is more efficient than the other
well known method summing powers of 2.
3.3
Summing powers of 2
The digits in a base 2 numeral are coefficients in a sum of powers of 2. E.g. 10011
stands for
1 24 + 0 23 + 0 22 + 1 21 + 1 20 .
6
by 2 is 60, remainder 1.
by 2 is 30, remainder 0.
by 2 is 15, remainder 0.
by 2 is 7, remainder 1.
y 2 is 3, remainder 1.
y 2 is 1, remainder 1.
y 2 is 0, remainder 1.
ase 2 (or binary) numeral for
010001.
3.3
Summing powers of 2
The digits in a base 2 numeral are coefficients in a sum of powers of 2. E.g. 10011
stands for
1 24 + 0 23 + 0 22 + 1 21 + 1 20 .
6
Since the coefficients are 0 or 1, this expression is actually a sum of powers of 2, namely
24 + 21 + 20 = 16 + 2 + 1 = 19.
This gives another way to convert binary numerals to decimal.
Example: 11110010001
10
=
=
2 +2 +2 +2 +2 +2
1024 + 512 + 256 + 128 + 16 + 1
1937
3.4
3.6
Conversion to hex
1000 =
0001 = 1
0010 = 2
1001 =
1010 =
0011 = 3
0100 = 4
1011 =
1100 =
0101 = 5
0110 = 6
1101 =
1110 =
0111 = 7
1111 =
So, e.g.
chunks
11110010001 bre
1 1 1 1
100111
1011
110010
10011
101
10011
000000
1001100
1011111
Question 3.4 How would you use eight bits to represent a signed
integer?
A possible method: Use the leftmost bit to indicate whether the
number is positive or negative.
I
I
We still have that the first bit tells us the sign (1 for negative, 0 for
positive or zero).
Basic addition routines just work! (assuming the results are within
the right bounds).
The next bit to the right represents 2n2 , the next 2n3 and so on
all the way down to 20 . (These are as per normal binary.)
3.4
Base 2 is the native notation for computers because it requires only two symbols, 0
and 1. However, base 2 numerals are inconveniently long, so they are often rewritten in
a larger base to make them shorter.
The most convenient bases are 8 and 16
(octal and hexadecimal), because they require essentially no conversion from base 2.
All you have to do is break the binary numeral into chunks chunks of three symbols for octal and chunks of four symbols for
hexadecimal.
The three symbol chunks are then translated into
Questions
(b) 81
(c) 255
(d
0, 1, 2, 3, 4, 5, 6, 7
for octal, and the four symbol chunks are
translated into
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
for hexadecimal.
7
+ 20 = 16 + 2 + 1 = 19.
3.6
1110010001
9
+2 +2 +2 +2 +2
+ 512 + 256 + 128 + 16 + 1
8 and base 16
Conversion to hexadecimal
1000 = 8
0001 = 1
0010 = 2
1001 = 9
1010 = A
0011 = 3
0100 = 4
1011 = B
1100 = C
0101 = 5
0110 = 6
1101 = D
1110 = E
0111 = 7
1111 = F
So, e.g.
chunks
Questions
3.1
(0111)2 = (7)16 ,
(101)2 = (5)16 ,
so (1010111)2 = (57)16 .
1s
20 s
1
1
2s
1
2 s
1
4s
2
2 s
1
8s
3
2 s
So 7.625 = (111.101)2 .
1s
1
So (11.100001)2 = 2 + 1 +
1
2s
1
4s
1
8s
1
16 s
1
32 s
1
64 s
1
2
1
64
= 3.515625.
(0100)2 = (4)16 .