csaba bir o, em}od kov acs - matematikai és informatikai...
TRANSCRIPT
Number Systems
Csaba Biro, Emod Kovacs
Eszterhazy Karoly College
Autumn Semester 2015
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 1 / 29
Table of contents
1 Number SystemsArbitrary p-based number systemDecimal number systemBinary number systemOctal number systemHexadecimal number systembinary, octal, decimal and hexadecimal number systems
2 Horner’s method (Horner scheme)
3 Converting between different number basesConverting to 10Convering decimal numbersBinary, Octal and Hexadecimal numeral systemsNumbers stored in finite position
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 2 / 29
Arbitrary p-based number system
Digits:{0, 1, ..., p − 1}
General formula:
N =n∑
i=−m
aipi
where,0 ≤ ai < p; ai ∈ {0, 1, ..., p − 1}; i ,m, n ∈ Z
The value of the number N can be obtained by multiplying the value ofthe digits of their positional notations, and adding up all
Base
The base of a number determines the number of different digit symbols(numerals) and the values of digit positions
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 3 / 29
Decimal number system
Digits: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}Base: p = 10Notation: 54310 or 543d 1
N = 543, 21 in base 10 positional notation is:
N = 543, 21 = 5 ∗ 102 + 4 ∗ 101 + 3 ∗ 100 + 2 ∗ 10−1 + 1 ∗ 10−2.
General formula:
N =n∑
i=−m
ai10i
where,0 ≤ ai < 10; ai ∈ Z; i ,m, n ∈ Z
In N = 543, 21:
n = 2;m = 2; a−2 = 1; a−1 = 2; a0 = 3; a1 = 4; a2 = 5;
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 4 / 29
Binary number system
Digits: {0, 1}Base: p = 2Notation: 11102 , 1110b or (1110)2
N = 1110, 112 in base 2 positional notation is:
N = 1 ∗ 23 + 1 ∗ 22 + 1 ∗ 21 + 0 ∗ 20 + 1 ∗ 2−1 + 1 ∗ 2−2.
N = 14, 75
Gerneral formula:
N =n∑
i=−m
ai2i
where,ai ∈ {0, 1}; i ,m, n ∈ Z
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 5 / 29
Octal number system
Digists: {0, 1, 2, 3, 4, 5, 6, 7}Base: p = 8Notation: 7348 , 734o or (734)8
N = 437, 128 in base 8 positional notation is:
N = 4 ∗ 82 + 3 ∗ 81 + 7 ∗ 80 + 1 ∗ 8−1 + 2 ∗ 8−2.
N = 287, 15625
General formula:
N =n∑
i=−m
ai8i
where,ai ∈ {0, 1, 2, 3, 4, 5, 6, 7}; i ,m, n ∈ Z
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 6 / 29
Hexadecimal number system
Digits: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,A,B,C ,D,E ,F}Base: p = 16Notation: BABA16 , BABAh or (BABA)16
N = 7FA, 1216 in base 16 positional notation is:
N = 7 ∗ 162 + 15 ∗ 161 + 10 ∗ 160 + 1 ∗ 16−1 + 2 ∗ 16−2.
N = 2042, 0703125
General formula:
N =n∑
i=−m
ai16i
where,ai ∈ N; 0 ≤ ai < 16; i ,m, n ∈ Z;
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 7 / 29
Example
7C0 hexadecimal3700 octal
11111000000 binary
1984 decimal
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 8 / 29
binary, octal, decimal and hexadecimal number systems
decimal binary octal hexadecimal0 0 0 01 1 1 12 10 2 23 11 3 34 100 4 45 101 5 56 110 6 67 111 7 78 1000 10 89 1001 11 9
10 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E15 1111 17 F
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 9 / 29
Polynomial
univariate (one variable) - example: 1 + y + y2 + 3y5 ,1 + x + x2 + 3x5
bivariate (two variables) - example: 1 + xy + (xy)2 + 3(xy)5
Definition
Univariate polynomials have the form f (x) = a0 + a1x + a2x2 + ... + anx
n,where n ≥ 0 and n ∈ N , a0, . . . , an are real numbers, x is the variate. Oneterm of polyinomial is ajx
j , aj is the coefficient of x j and the a0 = a0x0 is
a constant term.
The degree of a polynomialThe degree of a polynomial is the highest degree of its terms.If an 6= 0 then the degree of f is n.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 10 / 29
Horner’s method
Horner, William George (1786- 1837), British mathematician.
f (x) = anxn + an−1x
n−1 + · · ·+ a1x + a0, n ≥ 1
number of multiplications: (n2 + n)/2number of additions: n
Horner’s method
f (x) = (...((anx + an−1)x + an−2)x + · · ·+ a1)x + a0
Both numbers are n.This solution is optimal!
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 11 / 29
Horner’s method -Example
Evaluate f (x) = x3 + 2x2 − 3x + 2for x = 3
1 ∗ 3 ∗ 3 ∗ 3 + 2 ∗ 3 ∗ 3− 3 ∗ 3 + 2 = 38
6 multiplications, 2 additions, 1 subtractionsHorner-scheme
((1 ∗ x + 2) ∗ x − 3) ∗ x + 2
((1 ∗ 3 + 2) ∗ 3− 3) ∗ 3 + 2 = 38
3 multiplications, 2 additions, 1 subtractions
1 2 −3 2x = 3 3 15 36
1 5 12 38
The entries in the third row are the sum of those in the first two. Each entry in the second row
is the product of the x-value (3 in this example) with the third-row entry immediately to the
left. The entries in the first row are the coefficients of the polynomial to be evaluated.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 12 / 29
Converting to 10
Definition
If p > 1 is an integer number, in the p-based numeral system
(anan−1 . . . a1a0, a−1a−2 . . . a−m)p
p then its value in the decimal numeral system is
N =n∑
i=−m
aipi = anp
n + an−1pn−1 + · · ·+ a1p + a0 +
+a−1p−1 + · · ·+ a−mp
−m,
where ai ∈ Z es 0 ≤ ai < p, ,so ai ∈ {0, 1, 2, . . . , p − 1}.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 13 / 29
Examples
(123, 12)4 = 1 ∗ 42 + 2 ∗ 4 + 3 + 1 ∗ 4−1 + 2 ∗ 4−2 =
= 16 + 8 + 3 + 0, 25 + 0, 125 = 27, 375
(123, 12)8 = 1 ∗ 82 + 2 ∗ 8 + 3 + 1 ∗ 8−1 + 2 ∗ 8−2 = 83, 15625
(123, 12)16 = 1 ∗ 162 + 2 ∗ 16 + 3 + 1 ∗ 16−1 + 2 ∗ 16−2 = 29118
256= 291
9
128.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 14 / 29
Convering decimal numbers
Regard any N decimal number. The integer part of N is integer in anypositional notation numeral system, and the fraction part is a fraction. Sowe convert the integer part and the fraction part separately. So let?s
N = N0 + T0
where N0 indicate the integer part, T0 indicate the fraction part.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 15 / 29
Converting the integer part- Example
Convert 123 to the Octal numeral system.
123 : 8 = 15 es remains 3,15 : 8 = 1 es remanins 7,1 : 8 = 0 and remains 1.
For the above algorithm it is well-known the formula below, where thequotient goes to the left, the remain to the right and the digits will beread from below to above.123 ÷ 8
15 31 70 1 123 = (173)8
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 16 / 29
Converting the integer part- Example
Convert the 123 to Hexadecimal numeral system.
123 ÷ 16
7 B0 7 123 = (7B)16
It is important to indicate the algorithm is finite.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 17 / 29
Converting the fractional part-Example
Convert the 0, 6875 to Octal numeral system.
0, 6875 ∗ 8 = 5, 5000 = 5 + 0, 5
0, 5 ∗ 8 = 4, 0000 = 4
We may write the procedure in a more simple form.
0 , 6875 ∗ 8
5 5000 ∗ 84 0000 0, 6875 = (0, 54)8
Reading out is from the above to below at the integers on the left.Opposite the preceding algorithm, the procedure might be not ends by thefractional part becomes zero, since the decimal number written its finiteform is not always could be written in finite form in another numeralsystem.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 18 / 29
Converting the fractional part-Example
Convert the 0, 6875 by the above algorithm to Binary numeral system.
0 , 6875 ∗ 2
1 3750 ∗ 20 7500 ∗ 21 5000 ∗ 21 0000 0, 6875 = (0, 1011)2
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 19 / 29
Converting the fractional part-Example
Convert the 0, 2175 to Hexadecimal numeral system.
0 , 2175 ∗ 16
3 4800 ∗ 167 6800 ∗ 16A 8800 ∗ 16E 0800 ∗ 161 2800 ∗ 164 4800...
...0, 2175 = (0, 37AE147AE14 . . .)16
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 20 / 29
Binary, Octal and Hexadecimal numeral systems
Instead of applying long converting algorithms we get done the convers-ion by simply creating groups. We utilize that both 8 and 16 is an integerpower of 2. Namely 23 = 8 and 24 = 16.
According to this when we want to convert a binary number we have tomake groups from the digits left and right from the ”binary-point” (whichdivides the integer part from the fractional part) triad (group of three) andtetrad (group of four) what is match for one Octal or Hexadecimal digit.
The algorithm works backwards too.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 21 / 29
Binary, Octal and Hexadecimal numeral systems
Octal Binarydigit triad
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Hexadec. Binarydigit tetrad
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
Hexadec. Binarydigit tetrad
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 22 / 29
Binary, Octal and Hexadecimal numeral systems- Example
(123, 54)8 = 001 010 011 , 101 1001 2 3 , 5 4
Check the result by converting back both numbers into decimal:
(123, 54)8 = 1 ∗ 64 + 2 ∗ 8 + 3 ∗ 1 +5
8+
4
64= 83
44
64= 83, 6875
(1010011, 1011)2 = 1 ∗ 64 + 1 ∗ 16 + 1 ∗ 2 + 1 +1
2+
1
8+
1
16= 83
11
16= 83, 6875 .
Convert back the binary number using the tetrads to hexadecimal numeralsystem:
(1010011, 1011)2 = 0101 0011 , 10115 3 , B
which is in decimal
(53,B)16 = 5 ∗ 16 + 3 ∗ 1 +11
16= 83, 6875 .
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 23 / 29
Binary, Octal and Hexadecimal numeral systems- Example
During the backwards conversion we might need additional zeros in orderto create the triads or tetrads. Forgetting this causes often an error. Forexample (11, 101)2 6= (3, 5)16 , the correct solution is the following:
(11, 101)2 = 0011 , 10103 , A
bit
The positions in binary numeral system where either 0 or 1 could bewritten we call bit, as the abbreviation of the binary digit.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 24 / 29
Numbers stored in finite position
In everyday life on dashboards, or on machines display we could meetmany kinds of counters. For example the mileage counter on cars showsthe values on 6 positions.
9 9 9 9 9 9
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 25 / 29
Numbers stored in finite position
In computer science is common problem that in a given position we haveto determine the greatest and smallest representable number. Let?s h thenumber of positions p is the base number of the numeral system.
(anan−1 . . . a1a0, a−1a−2 . . . a−m)p
In case ofh = n + 1 + m.
We get the greatest number, when in every position is (p − 1) so,
Nmax =n∑
i=−m
(p − 1)pi = (p − 1)(pn + pn−1 + · · ·+ p−m).
Nmax = (p − 1)p−m pm+n+1 − 1
p − 1= pn+1 − p−m.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 26 / 29
Numbers stored in finite position
If the number does not have fractional part (m = 0) , then h = n + 1 and
Nmax = ph − 1.
For example in case h = 6:Decimal: 106 − 1 = 999999,Binary: 26 − 1 = 64− 1 = 63 = (111111)2. If the numbers fractionalpart left over, so the integer part is zero, then n + 1 = 0 so (h = m) and
Nmax = 1− p−h,
so in case of h = 6Decimal: 1− 10−6 = 0, 999999Binary: 1− 2−6 = (0.111111)2.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 27 / 29
Numbers stored in finite position
The question comes to mind: in what based numeral system could werepresent by the fewest notation the set of numbers which containsmaximum N identicalnumbers.
Thesis
That p value on which based a numeral system, by the fewest notation wecould represent the set containing N identical numbers is the base ofnatural based logarithm.
ln p = 1, azaz p = e ≈ 2, 71...
Because the physical implementation as we indicated before, it isreasonable that in computer science we use the p = 2 based 0, 1 note-setbinary numeral system. There were experiments to create computers basedon p = 3 numeral systems but they did not worked well.
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 28 / 29
Thank you for your kindly attentions!
Csaba Biro, Emod Kovacs (EKC) Szamrendszerek Autumn Semester 2015 29 / 29