The implementation is as follows:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace consoleapplication1
{
Public class number
{
Public String characters
{
Get;
Set;
}
Public int Length
{
Get
{
If (characters! = NULL)
Return Characters. length;
Else
Return 0;
}
}
Public number ()
{
Characters = "0123456789 ";
}
Public number (string characters)
{
Characters = characters;
}
/// <Summary>
/// Convert a number to a specified hexadecimal string
/// </Summary>
/// <Param name = "Number"> </param>
/// <Returns> </returns>
Public String tostring (long number)
{
List <string> result = new list <string> ();
Long T = number;
While (T> 0)
{
VaR mod = T % length;
T = math. Abs (T/length );
VaR character = characters [convert. toint32 (MOD)]. tostring ();
Result. insert (0, character );
}
Return string. Join ("", result. toarray ());
}
/// <Summary>
/// Convert a specified string to a specified numeric format
/// </Summary>
/// <Param name = "str"> </param>
/// <Returns> </returns>
Public long fromstring (string Str)
{
Long result = 0;
Int J = 0;
Foreach (var ch in new string (Str. tochararray (). Reverse (). toarray ()))
{
If (characters. Contains (CH ))
{
Result + = characters. indexof (CH) * (long) math. Pow (length, j ));
J ++;
}
}
Return result;
}
}
Class Program
{
Static void print (long number, number adapter)
{
Console. writeline ("input number: {0}", number );
Console. writeline ("rule: {0} \ t hexadecimal: {1} hexadecimal", Adapter. characters, Adapter. Length );
VaR numtostr = Adapter. tostring (number );
Console. writeline ("Conversion Result: {0}", numtostr );
VaR strtonum = Adapter. fromstring (numtostr );
Console. writeline ("reverse Conversion Result: {0}", strtonum );
Console. writeline ();
Console. writeline ("=============== boring split line =============== ");
Console. writeline ();
}
Static void main (string [] ARGs)
{
// The traditional BINARY SYSTEM
Number n1 = new number ("01 ");
// Traditional octal
Number n2 = new number ("01234567 ");
// Traditional hexadecimal
Number N3 = new number ("0123456789 abcdef ");
// Custom encoding in the n-base format. Can this be used for verification code?
Number N4 = new number ("My aunt said the name is too long to be found by the tribe after the tree ");
// Shanzhai a short website
Number N5 = new number ("0123456789 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ");
Print (65535, N1 );
Print (65535, N2 );
Print (65535, N3 );
Print (65535, N4 );
Print (165535, N5 );
Console. readkey ();
}
}
}