Number Bases.mws

High School Modules > Precalculus

     Number Bases


An exploration of alternative number bases, conversions, and even decimal expansions.

[Directions : Execute the Code Resource section first. Although there will be no output immediately, these definitions are used later in this worksheet.]

  0. Code

>    restart;

>    #===========================================================
printbase := proc( dec_num, bs)
   local x,n;
   x := convert( dec_num, base, bs );
   n := nops(x);  
   print( cat(dec_num,` = `,seq( x[n-i+1], i = 1..n),`  <base `,bs,`>`   ) );
end proc :

>    #===========================================================
print2base := proc( dec_num, bs1, bs2 )
   local x,n, y, m, k;
   x := convert( dec_num, base, bs1 );
   n := nops(x);
   if(bs1 = 16) then for k from 1 to n do
          if(x[k] = 10) then x[k] :=`A`; fi;
          if(x[k] = 11) then x[k] :=`B`; fi;
          if(x[k] = 12) then x[k] :=`C`; fi;
          if(x[k] = 13) then x[k] :=`D`; fi;
          if(x[k] = 14) then x[k] :=`E`; fi;
          if(x[k] = 15) then x[k] :=`F`; fi;
   od;fi;
   
   y := convert( dec_num, base, bs2 );
   m := nops(y);  
   print( cat(dec_num,` = `,seq( x[n-i+1], i = 1..n),`  <base `,bs1,`> = `,
                            seq( y[m-i+1], i = 1..m),`  <base `,bs2,`>`   ) );
end proc :

>    #===========================================================
basefraction := proc(num, bse, places)
   local k, kstart, x,q,xint,xdec,n,m;
   x := num;
   xint := [];   xdec := [];
   kstart := round(log[bse](x));
   for k from kstart to 0 by -1 do
     q := floor( x / bse^k);
     x := x - q* bse^k;
     xint := [op(xint),q];     
   od;

   for k from -1 to -places by -1 do
       q := floor( x / bse^k);
       x := x - q* bse^k;
       xdec := [op(xdec),q];  
   od;
   n := nops(xint);    m := nops(xdec);
   print( cat( seq( xint[i], i = 1..n),`.`,
               seq( xdec[m-i+1], i = 1..m),` <base `,bse,`>`));
end proc:

>    #===========================================================

  1. What Are Number Bases?


In our normal base 10 number system, which is called the decimal system, we have 10 digits : 0, 1, 2, ...9. There is no single symbol for the number one larger than nine, ten. We use two digits to represent this number, and so forth. The "1" in "10" represents one ten.

>    for k from 1 to 12 do k; od;

1

2

3

4

5

6

7

8

9

10

11

12


Eventually we need three digits. The "1" in "100" represents one ten squared.

>    for k from 96 to 102 do k; od;

96

97

98

99

100

101

102


What does the expression,  732 mean? Just as we can express an integer as a sum of numbers times powers of 10.

>    732 = `700` + `30`+ `2`;

732 = `700`+`30`+`2`

>    732 = `7 * 10^2`     +   `3 * 10^1`+   `2 * 10^0` ;

732 = `7 * 10^2`+`3 * 10^1`+`2 * 10^0`

 
In general, a five digit integer,
a[5] a[4] a[3] a[2] a[1] a[0] , can be expressed in this way

>    a:= 'a':  k:= 'k':
sum( a[k]*`10`^k, k = 0..5);

a[0]+a[1]*`10`+a[2]*`10`^2+a[3]*`10`^3+a[4]*`10`^4+a[5]*`10`^5


Our entire number system is based on 10 digits. However, this same process can occur with other number bases. Lets use base 7 as a an example. This means we will have digits 0, 1, 2, 3, 4, 5, 6. The number "7" will require two digits to represent.

>    for k from 1 to 16 do printbase( k, 7); od;

`1 = 1  <base 7>`

`2 = 2  <base 7>`

`3 = 3  <base 7>`

`4 = 4  <base 7>`

`5 = 5  <base 7>`

`6 = 6  <base 7>`

`7 = 10  <base 7>`

`8 = 11  <base 7>`

`9 = 12  <base 7>`

`10 = 13  <base 7>`

`11 = 14  <base 7>`

`12 = 15  <base 7>`

`13 = 16  <base 7>`

`14 = 20  <base 7>`

`15 = 21  <base 7>`

`16 = 22  <base 7>`


A number,
a[5] a[4] a[3] a[2] a[1] a[0]  considered to be in base 7, represents the following number.

>    a:= 'a':  k:= 'k':
sum( a[k]*`7`^k, k = 0..5);

a[0]+a[1]*`7`+a[2]*`7`^2+a[3]*`7`^3+a[4]*`7`^4+a[5]*`7`^5



When we look at numbers base 3, we only have 3 digits : 0, 1, and 2.  

>    for k from 1 to 16 do printbase( k, 3); od;

`1 = 1  <base 3>`

`2 = 2  <base 3>`

`3 = 10  <base 3>`

`4 = 11  <base 3>`

`5 = 12  <base 3>`

`6 = 20  <base 3>`

`7 = 21  <base 3>`

`8 = 22  <base 3>`

`9 = 100  <base 3>`

`10 = 101  <base 3>`

`11 = 102  <base 3>`

`12 = 110  <base 3>`

`13 = 111  <base 3>`

`14 = 112  <base 3>`

`15 = 120  <base 3>`

`16 = 121  <base 3>`

>    a:= 'a':  k:= 'k':
sum( a[k]*`3`^k, k = 0..5);

a[0]+a[1]*`3`+a[2]*`3`^2+a[3]*`3`^3+a[4]*`3`^4+a[5]*`3`^5


 

  2. Converting from Other Bases to Decimal


If we are given a number in another base, its not too difficult to convert it back to decimal, if we remember what the digits of the number in the other base mean. A four digit number in base 7 means the following.

>    'a[3]','a[2]','a[1]','a[0]',` <base 7>  ` = sum( a[k]*`7`^k, k = 0..3);

a[3], a[2], a[1], a[0], ` <base 7>  ` = a[0]+a[1]*`7`+a[2]*`7`^2+a[3]*`7`^3



         
Example 2.1:   Express 23 <base 7> in decimal.

3 is in the 1's place, and 2 is in the 7's place. So we just write out a sum like this, and verify it.

>    2*7 + 3;

17

>    printbase( 17, 7);

`17 = 23  <base 7>`


        
Example 2.2:   Express 54 <base 7> in decimal.

4 is in the 1's place, and 5 is in the 7's place. So we just write out a sum like this, and verify it.

>    5*7 + 4;

39

>    printbase( 39, 7);

`39 = 54  <base 7>`



        
Example 2.3:   Express 416 <base 7> in decimal.

This number has three digits. These numbers represent the number of 1's, 7's and 49's.

>    4*7^2 + 1*7 + 6;

209

>    printbase( 209, 7);

`209 = 416  <base 7>`


 
     
Example 2.4:   Express 416 <base 13> in decimal.

Same number as above, but a different base. So we expand it in the same way, but use the different base for the powers.

>    4*13^2 + 1*13 + 6;

695

  3. Converting from Decimal to Other Bases


Its slightly harder to convert from decimal to another base. Lets go through an example.


     
Example 3.1:   Express the decimal number 29 in base 9.

We can find the answer quickly using this function. The answer is 32 <base 9>. But how can find that for ourselves?

>    printbase( 29, 9);

`29 = 32  <base 9>`


We find the largest power of 9 that goes into 29 but does not exceed it. In this case, that power is 9^1. When we divide by 9 (throwing away any remainder for now), we get 3. This is the first digit our number in base 9.

>    dec_num := 29;
floor( dec_num/ 9^3);
floor( dec_num/ 9^2);
floor( dec_num/ 9^1);

dec_num := 29

0

0

3


This means that 3 is the digit in the "9's" place. We take 3*9^1 away from our number, what's left over are the number of ones. This gives us the whole number.

>    dec_num - 3*9^1;
print(`29 = 32 <base 9>`);

2

`29 = 32 <base 9>`

  

        Example   3.2:    Express the decimal number 78 in base 4.

We follow the same procedure as above. Find the greatest power of 4 that does not exceed the number, and divide that power into the number to get a digit. Then take the difference, and continue with smaller and smaller powers of 4, until we get to the ones place.

>    dec_num := 78;
floor( dec_num/ 4^4);
floor( dec_num/ 4^3);
floor( dec_num/ 4^2);
floor( dec_num/ 4^1);

dec_num := 78

0

1

4

19

 
The largest power of 4 that goes into 78 is 4^3, and it goes in, 1 time. The first digit is 1. Now look at the difference, and divide by the next smaller power of 4.

>    dec_num - 1*4^3;
floor( %/ 4^2);

14

0

>    %% - 0*4^2;
floor( %/ 4^1);

14

3

>    %% - 3*4^1;
floor( %/ 4^0);

2

2


So the digits are 1032 <base 4>.   Lets check.

We can check using this function, ...

>    printbase( 78, 4);

`78 = 1032  <base 4>`


    ... or Maple's built in converter, which gives us the digits as a list, in inverted order.

>    convert( 78, base, 4 );

[2, 3, 0, 1]


 

  4. Binary


One special number is base 2, which is called the
binary  number system. Every binary number is made up only 0's and 1's. This is a very simple system, but one which is immensely important - especially in the design and operation of computers where the smallest storage unit on a hard disk or in ram is a bit which is either on or off... 0 or 1.

>    for k from 0 to 16 do printbase( k, 2); od;

`0 =   <base 2>`

`1 = 1  <base 2>`

`2 = 10  <base 2>`

`3 = 11  <base 2>`

`4 = 100  <base 2>`

`5 = 101  <base 2>`

`6 = 110  <base 2>`

`7 = 111  <base 2>`

`8 = 1000  <base 2>`

`9 = 1001  <base 2>`

`10 = 1010  <base 2>`

`11 = 1011  <base 2>`

`12 = 1100  <base 2>`

`13 = 1101  <base 2>`

`14 = 1110  <base 2>`

`15 = 1111  <base 2>`

`16 = 10000  <base 2>`


Note that the powers of 2 are the "10", "100", "1000", etc. of this number base.

>    for k from 0 to 20 do printbase( 2^k, 2); od;

`1 = 1  <base 2>`

`2 = 10  <base 2>`

`4 = 100  <base 2>`

`8 = 1000  <base 2>`

`16 = 10000  <base 2>`

`32 = 100000  <base 2>`

`64 = 1000000  <base 2>`

`128 = 10000000  <base 2>`

`256 = 100000000  <base 2>`

`512 = 1000000000  <base 2>`

`1024 = 10000000000  <base 2>`

`2048 = 100000000000  <base 2>`

`4096 = 1000000000000  <base 2>`

`8192 = 10000000000000  <base 2>`

`16384 = 100000000000000  <base 2>`

`32768 = 1000000000000000  <base 2>`

`65536 = 10000000000000000  <base 2>`

`131072 = 100000000000000000  <base 2>`

`262144 = 1000000000000000000  <base 2>`

`524288 = 10000000000000000000  <base 2>`

`1048576 = 100000000000000000000  <base 2>`


Maple has a built-in command to quickly convert from decimal to binary, or vice-versa, from binary to decimal.

>    convert( 59,binary);

111011

>    convert( 111011, decimal,   binary );

59


 

  5. Octal


One problem with the binary system is that the numbers get so big so fast.
Octal , base 8, is a way to get a better grip on binary numbers because every three binary digits can be transformed into a single octal digit. Thus a 21 digit binary number can be expressed as a 7 digit octal number. In computer usage, every 3 bits can be represented by a single octal character. For example, 64 bit word, would take 64 binary digits to represent, or 22 octal digits. Its not just the smaller number of digits, but also the fact that you can convert binary to octal and vice-versa directly in your head without any formula.
 

>    for k from 1 to 16 do print2base( k, 2, 8); od;

`1 = 1  <base 2> = 1  <base 8>`

`2 = 10  <base 2> = 2  <base 8>`

`3 = 11  <base 2> = 3  <base 8>`

`4 = 100  <base 2> = 4  <base 8>`

`5 = 101  <base 2> = 5  <base 8>`

`6 = 110  <base 2> = 6  <base 8>`

`7 = 111  <base 2> = 7  <base 8>`

`8 = 1000  <base 2> = 10  <base 8>`

`9 = 1001  <base 2> = 11  <base 8>`

`10 = 1010  <base 2> = 12  <base 8>`

`11 = 1011  <base 2> = 13  <base 8>`

`12 = 1100  <base 2> = 14  <base 8>`

`13 = 1101  <base 2> = 15  <base 8>`

`14 = 1110  <base 2> = 16  <base 8>`

`15 = 1111  <base 2> = 17  <base 8>`

`16 = 10000  <base 2> = 20  <base 8>`


Note that the powers of 8 are the "10", "100", "1000", etc. of this number base.

>    for k from 0 to 6 do printbase( 8^k, 2); od;

`1 = 1  <base 2>`

`8 = 1000  <base 2>`

`64 = 1000000  <base 2>`

`512 = 1000000000  <base 2>`

`4096 = 1000000000000  <base 2>`

`32768 = 1000000000000000  <base 2>`

`262144 = 1000000000000000000  <base 2>`


Note that every three zeroes in the binary representation are a single zero in the octal representation.

>    for k from 0 to 10 do print2base( 8^k, 8, 2); od;

`1 = 1  <base 8> = 1  <base 2>`

`8 = 10  <base 8> = 1000  <base 2>`

`64 = 100  <base 8> = 1000000  <base 2>`

`512 = 1000  <base 8> = 1000000000  <base 2>`

`4096 = 10000  <base 8> = 1000000000000  <base 2>`

`32768 = 100000  <base 8> = 1000000000000000  <base 2>`

`262144 = 1000000  <base 8> = 1000000000000000000  <base 2>`

`2097152 = 10000000  <base 8> = 1000000000000000000000  <base 2>`

`16777216 = 100000000  <base 8> = 1000000000000000000000000  <base 2>`

`134217728 = 1000000000  <base 8> = 1000000000000000000000000000  <base 2>`

`1073741824 = 10000000000  <base 8> = 1000000000000000000000000000000  <base 2>`





Maple has a built-in command to quickly convert from decimal to octal, or vice-versa, from octal to decimal.

>    convert( 59,octal);

73

>    convert( 73, decimal,   octal );

59



You can convert from octal to binary by passing through the decimal expansion.

>    convert( 73, decimal,   octal );
convert( %, binary);

59

111011


You can convert from binary to octal in this way too.

>    convert( 1001001, decimal,   binary );
convert( %, octal);

73

111


 

  6. Hexadecimal


Hexadecimal  is base 16, and is even more useful than octal in representing binary numbers in a concise way. This is because each hexadecimal symbol represents 4 bits, or 4 binary digits. A 64 bit storage location can be stored with 64 bits, or "16 hex" symbols. This is a much more readable form of binary. And like octal, its not too hard to convert from binary to hex and back on the spot without formulas.

One problem with hex, that was not encountered with octal and binary, is that 16 is larger than 10, the base of our decimal system. This means we need 16 single symbols, but our decimal number system only provides 10 - we are six short. To make up for the shortage, it is customary to employ the first 6 letters of the alphabet :
               A = 10,     B = 11,     C = 12,    D = 13,    E = 14,    F = 15

>    for k from 1 to 15 do convert(k,hex); od;

`1`

`2`

`3`

`4`

`5`

`6`

`7`

`8`

`9`

A

B

C

D

E

F


We use these letters just like numbers. It takes a little getting used to seeing this strings of numbers and letters as numbers.

>    for k from 1 to 32 do print2base( k, 16, 2); od;

`1 = 1  <base 16> = 1  <base 2>`

`2 = 2  <base 16> = 10  <base 2>`

`3 = 3  <base 16> = 11  <base 2>`

`4 = 4  <base 16> = 100  <base 2>`

`5 = 5  <base 16> = 101  <base 2>`

`6 = 6  <base 16> = 110  <base 2>`

`7 = 7  <base 16> = 111  <base 2>`

`8 = 8  <base 16> = 1000  <base 2>`

`9 = 9  <base 16> = 1001  <base 2>`

`10 = A  <base 16> = 1010  <base 2>`

`11 = B  <base 16> = 1011  <base 2>`

`12 = C  <base 16> = 1100  <base 2>`

`13 = D  <base 16> = 1101  <base 2>`

`14 = E  <base 16> = 1110  <base 2>`

`15 = F  <base 16> = 1111  <base 2>`

`16 = 10  <base 16> = 10000  <base 2>`

`17 = 11  <base 16> = 10001  <base 2>`

`18 = 12  <base 16> = 10010  <base 2>`

`19 = 13  <base 16> = 10011  <base 2>`

`20 = 14  <base 16> = 10100  <base 2>`

`21 = 15  <base 16> = 10101  <base 2>`

`22 = 16  <base 16> = 10110  <base 2>`

`23 = 17  <base 16> = 10111  <base 2>`

`24 = 18  <base 16> = 11000  <base 2>`

`25 = 19  <base 16> = 11001  <base 2>`

`26 = 1A  <base 16> = 11010  <base 2>`

`27 = 1B  <base 16> = 11011  <base 2>`

`28 = 1C  <base 16> = 11100  <base 2>`

`29 = 1D  <base 16> = 11101  <base 2>`

`30 = 1E  <base 16> = 11110  <base 2>`

`31 = 1F  <base 16> = 11111  <base 2>`

`32 = 20  <base 16> = 100000  <base 2>`


Note that the powers of 16 are the "10", "100", "1000", etc. of the hex base. Note that each 0 in the hex number corresponds to four zeroes in the binary representation.

>    for k from 0 to 6 do print2base( 16^k, 16, 2); od;

`1 = 1  <base 16> = 1  <base 2>`

`16 = 10  <base 16> = 10000  <base 2>`

`256 = 100  <base 16> = 100000000  <base 2>`

`4096 = 1000  <base 16> = 1000000000000  <base 2>`

`65536 = 10000  <base 16> = 10000000000000000  <base 2>`

`1048576 = 100000  <base 16> = 100000000000000000000  <base 2>`

`16777216 = 1000000  <base 16> = 1000000000000000000000000  <base 2>`




Maple has a built-in command to quickly convert from decimal to octal, or vice-versa, from octal to decimal.

>    convert( 59, hex);

`3B`

>    convert( 200, hex);

C8

>    convert( 1000, decimal,   hex );

4096

>    convert( A0B0C, decimal,   hex );

658188


Conversions between binary and octal, and binary and hex are simple and can be done on inspection because each three binary digits can be represented by one octal digit, and each four binary digits can be represented by a single hex digit. However, the conversions from octal to hex are usually not particularly nice.

>    print2base( 333, 16, 8);

`333 = 14D  <base 16> = 515  <base 8>`

>    print2base( 1000, 16, 8);

`1000 = 3E8  <base 16> = 1750  <base 8>`

>    print2base( 1121210, 16, 8);

`1121210 = 111BBA  <base 16> = 4215672  <base 8>`


Except when the number is a power of two or near to one....

>    print2base( 512, 16, 8);

`512 = 200  <base 16> = 1000  <base 8>`

>    print2base( 257, 16, 8);

`257 = 101  <base 16> = 401  <base 8>`


 

  7. Computer Storage


Since all computer storage are based on binary, the sizes uses for hard disks, ram (random access memory), CD Rom, etc, is often measured in convenient powers of 2.

>    `1 k`   = 2^10;

`1 k` = 1024

>    `1 meg` = 2^20;

`1 meg` = 1048576

>    `1 gig` = 2^30;

`1 gig` = 1073741824


 You might notice that 1 meg, is 1 k squared, and 1 gig is 1024 megs.

  8. Decimals in Decimal


What does the expression,  732.145 mean? Just as we can express an integer as a sum of numbers times powers of 10, we can extend this to negative exponents too.

>    732.145 = `700` + `30`+ `2`+ `0.1`+ `0.04`+ `0.005`;

732.145 = `700`+`30`+`2`+`0.1`+`0.04`+`0.005`

>    732.145 = `7 * 10^2`     +   `3 * 10^1`+   `2 * 10^0`  +
          `1 * 10^(-1)`  +   `1 * 10^(-2)`+ `1 * 10^(-3)`;

732.145 = `7 * 10^2`+`3 * 10^1`+`2 * 10^0`+`1 * 10^(-1)`+`1 * 10^(-2)`+`1 * 10^(-3)`

 
In general, an integer,
a[5] a[4] a[3] a[2] a[1] a[0] , can be expressed in this way

>    a:= 'a':  k:= 'k':
sum( a[k]*`10`^k, k = 0..5);

a[0]+a[1]*`10`+a[2]*`10`^2+a[3]*`10`^3+a[4]*`10`^4+a[5]*`10`^5


In the same way, a decimal number,
a[4] a[3] a[2] a[1] a[0] . a[-1] a[-2] , can be expressed in this way

>    a:= 'a':  k:= 'k':
sum( a[k]*`10`^k, k = -2..4);

a[-2]/`10`^2+a[-1]/`10`+a[0]+a[1]*`10`+a[2]*`10`^2+a[3]*`10`^3+a[4]*`10`^4


Can we extend this same thinking to other number bases?
 

  9. Fractions in Binary


In the same way that we used negative powers base 10, we can do the same thing in binary, base 2.

>    for k from -4 to 5 do 1/2^k = convert( .5^k, binary),`<base 2>`; od;

16 = 10000., `<base 2>`

8 = 1000., `<base 2>`

4 = 100., `<base 2>`

2 = 10., `<base 2>`

1 = 1., `<base 2>`

1/2 = .1000000000, `<base 2>`

1/4 = .1000000000e-1, `<base 2>`

1/8 = .1000000000e-2, `<base 2>`

1/16 = .1000000000e-3, `<base 2>`

1/32 = .1000000000e-4, `<base 2>`



        Example 9.1 :   
Express 3/4 in base 2

Since 1/2 = .1 <base 2>, and 1/4 = .01 <base 2>, if we add 1/2 and 3/4, we should be able to add .10 and .01 to get .11 <base 2>.

>    1/2 + 1/4 : %= convert( evalf(%), binary),`<base 2>`;

3/4 = .1100000000, `<base 2>`


       Example 9.2 :    Express 7/8 in base 2

If we add the next power of 2, 1/8 ....

>    1/2 + 1/4 +1/8:  %= convert( evalf(%), binary),`<base 2>`;

7/8 = .1110000000, `<base 2>`


       Example 9.3 :    Express 15/16 in base 2

If we add the next power of 2, 1/16 ....

>    1/2 + 1/4 + 1/8 + 1/16:  %= convert( evalf(%), binary),`<base 2>`;

15/16 = .1111000000, `<base 2>`


       Example 9.4 :    Express 31/32 in base 2

If we add the next power of 2, 1/32 ....

>    1/2 + 1/4 +1/8 + 1/16 + 1/32:  %= convert( evalf(%), binary),`<base 2>`;

31/32 = .1111100000, `<base 2>`


       Example 9.5 :    Express 63/64  in base 2

If we add the next power of 2, 1/64 ....

>    1/2 + 1/4 +1/8  + 1/16 + 1/32 + 1/64:  %= convert( evalf(%), binary),`<base 2>`;

63/64 = .1111110000, `<base 2>`


 Any decimal number in base 10 can be expressed as a decimal in binary...although they may be infinite.
 
       Example 9.4 :    Express 1/3, 1/4, 1/5, 1/6, 1/7 in base 2

Notice that only one of these has a terminating decimal. Can you explain why?

>    1/3:  %= convert( evalf(%), binary),`<base 2>`;

1/3 = .1010101010e-1, `<base 2>`

>    1/4:  %= convert( evalf(%), binary),`<base 2>`;

1/4 = .1000000000e-1, `<base 2>`

>    1/5:  %= convert( evalf(%), binary),`<base 2>`;

1/5 = .1100110011e-2, `<base 2>`

>    1/6:  %= convert( evalf(%), binary),`<base 2>`;

1/6 = .1010101010e-2, `<base 2>`

>    1/7:  %= convert( evalf(%), binary),`<base 2>`;

1/7 = .1001001001e-2, `<base 2>`


        Example 9.5 :   
Express sqrt(2) in base 2 to 20 places.

We'll use the same process, but we'll automate it to take the drudgery out of the chore.

>    sqrt(2):  %= convert( evalf(%), binary),`<base 2>`;

2^(1/2) = 1.011010100, `<base 2>`


Good, but not enough decimal places. Lets try this custom function.

>    basefraction(evalf(sqrt(2)), 2, 30);

`1.100110011001111001000001010110 <base 2>`


Is there any pattern? Hopefully not, since sqrt(2) is an irrational number... which means irrational in all number bases, not just in base 10!

  10. Fractions in Other Bases


Of course, we can do the same thing in other number bases. Any decimal number base 10 can be represented by decimals in other number bases.

       Example   10.1 :    Express 10 4/7 in base 7.

This is a set up of course because we are given a denominator with 7 already in it.

>    `10 1/7` = cat( 1, 3, `.`,4,` <base 7>`);

`10 1/7` = `13.4 <base 7>`


OK, lets do one with a only little more substance.  

       Example 10.2 :    Express 5  25/49 in base 7.

Although it looks a bit different we use the same procedure we used to make conversions of integers above. Divide by the largest power of 7 that divides the number, take the difference, and continue the process. The 5 is already the 1's digit (7^0). As we progress to the next smaller exponent, we go to
7^(-1) , and divide.

>    floor( (25/49) / (7^(-1)) );

3

>    (25/49) - 3/7;

4/49

>    `5  25/49` = cat( 5, `.`,34,` <base 7>`);

`5  25/49` = `5.34 <base 7>`

 

    Example 10.3 :   
Express 1/2 in base 7.

Same process.

>    1/2;
floor( % / (7^(-1)) );
%% - %*(7^(-1));

1/2

3

1/14

>    floor( % / (7^(-2)) );
%% - %*(7^(-2));

3

1/98

>    floor( % / (7^(-3)) );
%% - %*(7^(-3));

3

1/686

>    basefraction( 1/2, 7, 12);

`0.333333333333 <base 7>`

We seem to have encountered a pattern. 1/2 has an infinite decimal in base 7, although it has a terminating decimal base 10.

>    `1/2` = `.333... <base 7>`;

`1/2` = `.333... <base 7>`




        Example 10.3 :   
Express ¹ in base 7 to 12 places.

We'll use the same process, but we'll automate it to take the drudgery out of the chore.

>    Pi; evalf(%, 30):
basefraction(%, 7, 12);

Pi

`03.212341563660 <base 7>`




        Example 10.4 :   
Express ¹ in base 3 to 20 places.

We'll use the same process, but we'll automate it to take the drudgery out of the chore.

>    Pi; evalf(%);
basefraction(%, 3, 20);

Pi

3.141592654

`10.20112010222210112010 <base 3>`



        Example 10.5 :   
Express sqrt(3) in base 3 to 30 places.

We'll use the same process, but we'll automate it to take the drudgery out of the chore.

>    sqrt(3); evalf(%);
basefraction(%, 2, 30);

3^(1/2)

1.732050808

`01.100001011101011110011011011101 <base 2>`

>   


         © 2002 Waterloo Maple Inc & Gregory Moore, all rights reserved.