base2base.exe BASE CONVERSION PROGRAM  JPG May 2002

base2base and base2base2 are programs that convert any input number in any base
from 2 to 67 to an output in any base over the same range. 
The two programs take identical input and
produce the same output. The differences are in the way the algorithm is written in C.
Both the integer and fractional parts of a number are converted, an improvement over 
the windows calculator which only coverts the integer parts of binary, decimal, and 
hexadecimal numbers.

The term 'digit' is used for characters of any base.  The digit characters are 1-10, 
A-Z, [, \, ], ^, -, ', a-z.  The characters from A to z are in ASCI order, hence the
odd symbols. A table of the characters, with the decimal value in the top row follows.
When working with bases greater than 10 (or 16), it is helpful to have a printout of 
this table for reference. Note that small letters have vastly different values than 
capitals. When working in hexadecimal, one must use capitals.  (There are more odd ASCI
characters available, but I thought z was a nice stopping place.)

Table of 'digit' characters:
 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
 0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F  G  H  I  J

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z  [  \  ]  ^

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
 _  `  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r

60 61 62 63 64 65 66 67
 s  t  u  v  w  x  y  z
 
After a table of the characters is printed, the user is asked for an input base. Entry of
a value less than or equal to zero exits the program. A value greater than 68 gives an
error message. A valid entry returns the highest (last) allowed digit for that base which is 
equal to the base-1. Entry of a non-integer may result in a program crash that requires
a Ctrl-C to get out of.

Next the process is repeated for an output base. A zero value will go back to the input base
entry.	For the output base, besides the last digit, the number of bits required to represent
a digit is given.  This information is used with the intout and fracout output values
described below.

Next a value in the input base is requested. If a character too large for the input base 
is given, an error message results. Entering zero will return to the request for an input 
base.

Next the output base is printed out and the converted value is given. The number of 'decimal' 
places varies with the base.  Sometimes, .500000 will approximate to .499999. If a value
too large to fit in 4 bytes was entered, an error message pointing that out is given.

For bases which are a power of two, the bits per digit are equal to that power. For bases
in between powers of two, the bits per digit are the same as the next highest power of two. 
For example, base 2, bits=1, base 4, bits=2, base 10, bits=4, base 16, bits=4. For power of
two bases, all the possible digits are used, for example, the 16 possible digits represented 
by 4 bits are used in hexadecimal. For base other than power of two there is some inefficiency, 
hence in base 10 (binary coded decimal), only 10 of the possible 16 four bit digits are used.
A base one larger than a power of two is most inefficient, for instance in base 33, only 33 
out of the possible 64 digits are used.

The intout value represents 4 bytes (32 bits),in right aligned hexadecimal, of the integer
part of the converted number. In the case of base 16 output, these values are the same as 
in the converted number. In this case, and all others with base between 9 and 16, the 
number of bits per digit is four.  In other cases, the bits per digit must be taken into 
account.  An example: 100=1X in base 67, (1x67+33)=100. intout= 00 00 00 A1h = 1010 0001= 
|0000001|0100001| with the bits grouped by 7, the bits per digit. inout=|1|33|=|1|X|, 
since 33=X from table above. 

For the fractional part, fracout works the same way except it is left aligned. Another 
example: 100.5=34.G in base 32, 3x32+4=100, (G=16)x(1/32)=0.5. Bits per digit=5. 
intout=64h=0110 0100=|00011|00100|=|3|4|, fracout=80h= 1000 0000=|10000|=16=G. 

Some general observations: 
1. All power of two output bases have the same bit pattern in ontout and fracout, only the 
grouping of the bits into digits changes.
2. A long repeating fraction in one base can be very simple in another base. e.g. 
.3333333333333333 (16 3's) in decimal gives .1 in base 3.
3. Any number expressed in a base equal to that number is 10. i.e. (decimal 23 in base 23)=10.
or (hex 23 in base 35)=10.

You may find bugs, if so let me know. jgoldsboro@aol.com
 