Introduction
If you are a programmer you know different positional numeral systems and deal with them on a daily basis. In everyday life we are usually satisfied with the base 10 numeral system, where we can express any number using 10 symbols (digits): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
But the computer world is quite different. The binary nature of computer storage, size of byte  the elementary storage unit, makes binary (base 2) system natural when dealing with computers. The only problem is that numbers expressed as binary make quite long strings for large numbers and they are not easy to read. Who knows that binary number 100100110010110000001011010010 is equivalent of decimal 1,234,567,890?
Hexadecimal (base 16) system comes to rescue and makes numbers shorter. The same decimal number 1,234,567,890 expressed as hexadecimal looks like: 499602D2. It's much shorter than the corresponding binary representation, but I bet you  it's not easy to tell what this number really represents in familiar to us humans decimal notation.
Truth is that to deal with numbers written in different positional numeral systems you need to have tools to help translate numbers from one base to another.
.NET Framework gives very little help.
Convert.ToString(int number, int base)
allows only to convert decimal representation of an integer to a different base only if the base is 2, 8, 10 or 16, And of course it can deal only with 32bit integers. Not a very generic solution.
Background
What I've decided to have is a library class that allows to:
 Convert integer number from any base representation to another base representation.
 Do not set limits to the size of the number.
Both statements are rather bold and sound unfeasible so they deserve a few words of explanation:
"Any base"  I said "any base" because there is nothing what in theory prevents us from encoding numbers using very high base numbers, greater than commonly used values 8, 16 or even 64. There is only one "but." To express the number as basex representation we need to use x distinct characters to represent digits within the number. For base 10 we use 0,1,2,3,4,5,6,7,9,0  no problem; for base16 we just add 6 more: A, B, C, D, E, F. There is no problem to find 64 (or even little more) distinct printable characters in English based character set, but how to write basex numbers where x is much greater than 64? One thing comes to mind: use Unicode character set for nonEnglish language. Perhaps Chinese characters? Other options are: use graphical objects for characters or colors or mixture of ideas mentioned above. Point is, that we are able to express numbers with written in numeral systems with very large base.
"No size limit"  this promise is very easy to fullfill. Net Framework 4.0 introduced new structure: BigInteger
. It allows to create and manipulate an arbitrary large integer numbers. Only limit is the size of available memory. After deciding to use BigInteger
to represent decimal representation of the number, conversion can be performed truly for number of any size.
Code Explained
I decided to wrap all functionality in static library class called IntegerBaseConverter
.
At hearth of the class lay two simple algorithms.
One to convert BigInteger
number to the string expressing same number in Basen numeral system (where n is a parameter of the algorithm).
public static string Convert(BigInteger value, int radix, string digits)
{
if ((radix > digits.Length)  (radix < 2))
throw new ArgumentOutOfRangeException("radix", radix,
string.Format("Radix has to be within range <2, {0}>;", digits.Length));
StringBuilder sb = new StringBuilder();
do
{
BigInteger remainder;
value = BigInteger.DivRem(value, radix, out remainder);
sb.Insert(0, digits[(int)remainder]);
} while (value > 0);
return sb.ToString();
}
And another one that converts Basen string representation of the number to the BigInteger
value.
public static BigInteger Parse(string value, int radix, string digits)
{
if ((radix > digits.Length)  (radix < 2))
throw new ArgumentOutOfRangeException("radix", radix,
string.Format("Radix has to be within range <2, {0}>;", digits.Length));
if (value == "")
value = digits.Substring(0,1);
BigInteger RetValue = 0;
for (int i = 0; i < value.Length; i++)
{
int CharIdx = digits.IndexOf(value[i]);
if ((CharIdx >= radix)  (CharIdx < 0))
throw new ArgumentOutOfRangeException("Value", digits[CharIdx], "Invalid character in the input string.");
RetValue = RetValue * radix + CharIdx ;
}
return RetValue;
}
Both methods are simple, selfexplanatory and algorithms are well known. I didn't invent a wheel here. I don't think any more explanation that code itself is necessary.
Just one quick note: Since word base is reserved word in C#, I decided to use word radix instead in my source code with the meaning "numeral system base" attached to it. In this article words base and radix are interchangeable and have identical meaning.
Using the code
IntegerBaseConverter
class exposes one public property:
Property 
Description 

DefaultDigitSet

Readonly property showing default character set representing digits used to write the number in numeral system.
By default it contains 64 character string of the following characters: "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,
N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,+,/.
Characters and their order are most commonly used characters for string representations of 
IntegerBaseConverter
also exposes the following public methods:
Method 
Description 

CanUseCaseInsensitiveParsingMode(string digits)

Returns true when there are no duplicate characters in 
Compare(Char digit1, Char digit2, String digits)

Compares two digits (characters). Order of digits is determined by order of characters in 
Compare(String number1, String number2, String digits)

Compares two numbers represented as strings encoded using the same 
Convert(BigInteger value, int radix, string digits)

Converts 
GetPaddedValue

Converts 
IsValidDigitSet(string digits)

Returns true when there are no duplicate characters in 
IsValidNumber(string number, string digits)

Verifies if 
MaxValue(Type type)

Returns 
MaxValue(Type type, int radix, string digits)

Returns string representation of maximum value of the number of 
Parse(string value, int radix, string digits)

Converts string representation of a number (written as radix base string) to its BigInteger equivalent. 
Parse(string number, int radix, string digits, bool CaseSensitiveParsing = true)

Parses string number representation of the number written in 
TryParse(string value, int radix, string digits, out BigInteger result, bool CaseSensitiveParsing = true)

Converts string representation of a number (written as 
Demo program
Downloadable demo program, help file and source code are attached to this article. You can use it to investigate and test behavior of the library and as a starting point to implement your own solution with IntegerBaseConverter
.
Note about help file:
Since you are downloading help file from the Internet, you need to unblock the file before you use it for the first time. Form the Windows Explorer rightclick on the file name , select 'Properties' and then click on 'Unblock' button.