Professional Documents
Culture Documents
Introduction
A numeral system (or system of numeration)
is a writing system for expressing numbers,
that is, a mathematical notation for
representing numbers of a given set, using
digits or other symbols in a consistent
manner.
It can be seen as the context that allows the
symbols "11" to be interpreted as the binary
symbol for three, the decimal symbol for
eleven, or a symbol for other numbers in
different bases.
Contents
1. Brief History
2. The Number Sense
3. Classification of Numbers
4. Number System(Definition)
5. Nth Number System
6. Decimal System
7. Binary System
8. Hexadecimal System
9. Does number system affect
rationality?
10.Conversion of Decimal to Binary
11.Motivation of the Algorithm
12.Proof of Correctness
13.C++ code Decimal to Nth conversion
algorithm
14.Conversion of Binary to Decimal
15.References
Brief History
Evolution of Numbers
The Greek
numbering
system was
uniquely
based upon
their
alphabet.
The original Greek alphabet consisted of 27 letters and
was written from the left to the right. These 27 letters
make up the main 27 symbols used in their numbering
system.
Problems with Ancient Number Systems1. In the above examples we see that to represent a
number we require a huge number of digits or
symbols. So to minimize the space required to
represent a number we need a more compact
numbering system. Space complexity is O(n). This
led to problems since not enough paper or rocks
were available.
2. No concept 0, neither the tally system nor the Roman
numeral system had the concept of 0.
3. No concept of bit addition. That is arithmetic
operations couldnt be done on individual digits
Sense of Numbers
The number sense is not the ability to count, but the ability to
recognize that something has changes in a small collection.
One might think people would have a very good number sense, but as it
turns out, people do not. Experiments have shown that the average
person has a number sense that is around four.
Classification of Numbers
Number Systems
A number system is a writing system for
expressing numbers, that is, a mathematical
notation for representing numbers of a given set,
using digits or other symbols in a consistent
manner.
The value of a number akak-1a1a0 which is in
base x system is given by (where 0ai<x for
0xk)
akx k + ak-1x
k-1
++a1x 1+a0x
Position
Magnitude
o Sum of Digit x Weight
Formal Notation
o ak10 k + ak-110k-1 + + a1101 + a0100
Example:
(493)10 = 4*102 + 9*101 + 3*100.
Positional Notation
Position
...
1000
100
10
0.1
0.01
...
...
Weight
Digit
Binary Digit
LSB
28
27
26
25
24
23
22
21
20
256
128
64
32
16
Common Name
Bit
Nibble
Byte
16
Word
Informal Way
1.Given a number N in decimal system.
2.Calculate the highest power of 2 which is less
than N. Let it be some K.
97
64
33
32
3
4
5
6
01
01
01
01
16
08
04
02
9764=33
3332=01
01
01
01
01
32
16
08
04
02
01
0
0
0
0
01
01
0100
1
01=00
Since N=0, stop here and dequeue from queue.
Procedural Way
Direction
of
Counting
Direction
of
Counting
15610 = 100111002
Eg: Lets convert 6710 into septal system.
Sol : Septal system have base =7.
Divide 67 by 7 and collect remainder. Divide the
quotient again by 7 and collect remainder and
repeat the procedure until we get quotient as 0.
Direction
of
Counting
Note that the numbers written after hyphen in each
row is the remainder of the corresponding division
performed. Write the remainders in the direction of
arrow mark and finally answer is
6710 = 1247
Direction
of
Counting
vi.
Sometimes for some numbers we may not
be able to get the fractional part=0, even after
so many steps. In that case, we get a precision
error. This is because, every fractional part
cannot be expressed as a sum of 0.5, 0.25,
0.125 and so on.
Direction of
Counting of
integer parts
Direction
of
Counting
Hence, 140410=57C16
20a0+21a1+22a2.2nan=
0+2*(20a1+21a2+22a32n-1an) = 0+2*(n/2)
If n is even this algorithm gives the right result.
If n is oddIf n is odd then the algorithm will write the final
answer (an an-1an-2a1)a0 (a1=1).
20a0+21a1+22a2.2nan =
1+2*(20a1+21a2+22a32n-1an) = 1+2*(n-1)/2= n
(since n is odd n/2 will evaluate to (n-1)/2 by the
algorithm)
If n is odd this algorithm gives the right result.
QED.
Proof of Conversion of Fractional PartFact 1The algorithm tries to find a binary representation
that is the closest to the fractional part and at the
same time is less than equal to the number. In
other words the number outputted by the
algorithm will not in any scenario be greater than
the number whose conversion we are trying to
find
We want to prove that the kth digit after decimal
printed by the algorithm is correct.
Proof by Induction
Here O refers to the original fractional number.
And Fk refers to the fractional number used by the
algorithm in the k step. For example In Binary
conversion of 0.54 O=0.54
And the next number that is used is 2*0.541=0.08=F2 since it used in the 2nd step.
Base case1st digit after decimal is correct and the F2= 2*O a-1.
O=a-1/2 +a-2/4 + a-3/8 .
a-2/4 + a-3/8.<= 1/4+1/8+1/16.=1/2
(Follows from the sum of an infinite GP)
if O>=1/2 the a-1 will be 1 ,else 0.
O*2>=1 then a-1 is 1 else 0 . (1) (This is what
the algorithm does)
If a-1 is 1 then clearly 2*O>=1 and F2=2*O-1
(assignment)
Else F2=2*O (assignment)
Inductive Step
Using induction we know that the algorithm at k-1
step uses
Fk-1 =2k-1O - 2k-2a-2 - 2k-3a-3 .-a-k+1
(2)
Using Original Equation
O=a-1/2 +a-2/4 + a-3/8. + a-k+1/2k-1 + a-k/2k + a-kk+1
1/2
Doing some manipulations we can reduce it to
2k-1O - 2k-2a-2 - 2k-3a-3 .-a-k+1 =a-k/2 +a-k-1/4
Using (2) we get
Fk-1=a-k/2 +a-k-1/4
This is equivalent to the base case and we can
use the same logic to prove that the algorithm
computes the k digit after decimal correctly and
also that
Fk =2*Fk-1 - a-k.
Fk = 2kO - 2k-1a-2 - 2k-4a-3 .-2*a-k+1-a-k
This proves the inductive step
QED
{
if(top<=num-1)
{
a[top++]=data;
}
else if(top==num-1)
{
num=num+5;
a=(int *)realloc(a,num*4);
a[top++]=data;
}
}
int pop()
{
if(top==-1)
cout<<"stack is empty"<<endl;
else
return a[--top];
}
int gettotal()
{
return (top+1);
}
};
int main()
{
int n,x,i;
float k,data,f;
stack a;
cout<<"enter a number : ";
cin>>data;
cout<<endl<<"Enter the destination number system:";
cin>>x;
n=(int)data; //storing integer part of data in n
f=data-n; //storing fractional part of data in f
while(n!=0)
{
a.push(n%x); //pushing the remainder
n=n/x; //updating the value of n
}
(anan-1an-2...a0.a-1a-2a-3...) 2 = a
0
2 +
a -k 2-k
1
Eg(101.11)2 = 1*22+0*21+1*20+1*2-1+1*2-2
= (5.75)10
Eg- Convert 1010110102 from binary to
decimal.
2 + 8 + 16 + 64 + 256 = 34610
Octal Number
Decimal Number
Step 1
258
Step 2
Step 3
258
258
(16 + 5 )10
2110
References
https://en.wikipedia.org/wiki/Numeral_syst
em
http://www.math.wichita.edu/history/topics
/num-sys.html
http://betterexplained.com/articles/numbe
rs-and-bases/
http://www.tutorialspoint.com/computer_fu
ndamentals/computer_number_conversion
.htm