public string IntToi64(long xx)
{
string a = "";
while(xx>=1)
{
int index = Convert.ToInt16(xx - (xx / 64) * 64);
a = Base64Code[index]+a;
xx = xx / 64;
}
return a;
}
public long i64ToInt(string xx)
{
long a = 0;
int power = xx.Length-1;
for(int i=0;i<=power;i++)
{
a += _Base64Code[xx[power - i].ToString()] * Convert.ToInt64( Math.Pow(64, i));
}
return a;
}
public static Dictionary<int, string> Base64Code = new Dictionary<int, string>() {
{ 0 ,"A"}, { 1 ,"B"}, { 2 ,"C"}, { 3 ,"D"}, { 4 ,"E"}, { 5 ,"F"}, { 6 ,"G"}, { 7 ,"H"}, { 8 ,"I"}, { 9 ,"J"},
{ 10 ,"K"}, { 11 ,"L"}, { 12 ,"M"}, { 13 ,"N"}, { 14 ,"O"}, { 15 ,"P"}, { 16 ,"Q"}, { 17 ,"R"}, { 18 ,"S"}, { 19 ,"T"},
{ 20 ,"U"}, { 21 ,"V"}, { 22 ,"W"}, { 23 ,"X"}, { 24 ,"Y"}, { 25 ,"Z"}, { 26 ,"a"}, { 27 ,"b"}, { 28 ,"c"}, { 29 ,"d"},
{ 30 ,"e"}, { 31 ,"f"}, { 32 ,"g"}, { 33 ,"h"}, { 34 ,"i"}, { 35 ,"j"}, { 36 ,"k"}, { 37 ,"l"}, { 38 ,"m"}, { 39 ,"n"},
{ 40 ,"o"}, { 41 ,"p"}, { 42 ,"q"}, { 43 ,"r"}, { 44 ,"s"}, { 45 ,"t"}, { 46 ,"u"}, { 47 ,"v"}, { 48 ,"w"}, { 49 ,"x"},
{ 50 ,"y"}, { 51 ,"z"}, { 52 ,"0"}, { 53 ,"1"}, { 54 ,"2"}, { 55 ,"3"}, { 56 ,"4"}, { 57 ,"5"}, { 58 ,"6"}, { 59 ,"7"},
{ 60 ,"8"}, { 61 ,"9"}, { 62 ,"+"}, { 63 ,"/"}, };
public static Dictionary<string, int> _Base64Code
{
get
{
return Enumerable.Range(0, Base64Code.Count()).ToDictionary(i => Base64Code[i], i => i);
}
}
找半天没一个能用的~只好自己写了~(ps: dictionary 的速度要比正常array快很多)
C# 10进制和64进制相互转换
最新推荐文章于 2024-07-23 21:37:15 发布