|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+using System;
|
|
|
2
|
+using System.Collections.Generic;
|
|
|
3
|
+using System.Linq;
|
|
|
4
|
+
|
|
|
5
|
+namespace Utility
|
|
|
6
|
+{
|
|
|
7
|
+ public class NumberConvert
|
|
|
8
|
+ {
|
|
|
9
|
+
|
|
|
10
|
+ public static string IntToJinZhi(long xx,int jinZhi)
|
|
|
11
|
+ {
|
|
|
12
|
+ string a = "";
|
|
|
13
|
+ while (xx >= 1)
|
|
|
14
|
+ {
|
|
|
15
|
+ int index = Convert.ToInt16(xx - (xx / jinZhi) * jinZhi);
|
|
|
16
|
+ a = Base64Code[index] + a;
|
|
|
17
|
+ xx = xx / jinZhi;
|
|
|
18
|
+ }
|
|
|
19
|
+ return a;
|
|
|
20
|
+ }
|
|
|
21
|
+
|
|
|
22
|
+ public static long JinZhiToInt(string xx,int jinZhi)
|
|
|
23
|
+ {
|
|
|
24
|
+ long a = 0;
|
|
|
25
|
+ int power = xx.Length - 1;
|
|
|
26
|
+
|
|
|
27
|
+ for (int i = 0; i <= power; i++)
|
|
|
28
|
+ {
|
|
|
29
|
+ a += _Base64Code[xx[power - i].ToString()] * Convert.ToInt64(Math.Pow(jinZhi, i));
|
|
|
30
|
+ }
|
|
|
31
|
+
|
|
|
32
|
+ return a;
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ public static Dictionary<int, string> Base64Code = new Dictionary<int, string>() {
|
|
|
36
|
+ { 0 ,"z"}, { 1 ,"1"}, { 2 ,"2"}, { 3 ,"3"}, { 4 ,"4"}, { 5 ,"5"}, { 6 ,"6"}, { 7 ,"7"}, { 8 ,"8"}, { 9 ,"9"},
|
|
|
37
|
+ { 10 ,"a"}, { 11 ,"b"}, { 12 ,"c"}, { 13 ,"d"}, { 14 ,"e"}, { 15 ,"f"}, { 16 ,"g"}, { 17 ,"h"}, { 18 ,"i"}, { 19 ,"j"},
|
|
|
38
|
+ { 20 ,"k"}, { 21 ,"x"}, { 22 ,"m"}, { 23 ,"n"}, { 24 ,"y"}, { 25 ,"p"}, { 26 ,"q"}, { 27 ,"r"}, { 28 ,"s"}, { 29 ,"t"},
|
|
|
39
|
+ { 30 ,"u"}, { 31 ,"v"}, { 32 ,"w"}, { 33 ,"x"}, { 34 ,"y"}, { 35 ,"z"}, { 36 ,"A"}, { 37 ,"B"}, { 38 ,"C"}, { 39 ,"D"},
|
|
|
40
|
+ { 40 ,"E"}, { 41 ,"F"}, { 42 ,"G"}, { 43 ,"H"}, { 44 ,"I"}, { 45 ,"J"}, { 46 ,"K"}, { 47 ,"L"}, { 48 ,"M"}, { 49 ,"N"},
|
|
|
41
|
+ { 50 ,"O"}, { 51 ,"P"}, { 52 ,"Q"}, { 53 ,"R"}, { 54 ,"S"}, { 55 ,"T"}, { 56 ,"U"}, { 57 ,"V"}, { 58 ,"W"}, { 59 ,"X"},
|
|
|
42
|
+ { 60 ,"Y"}, { 61 ,"Z"}, { 62 ,"-"}, { 63 ,"_"},
|
|
|
43
|
+ };
|
|
|
44
|
+
|
|
|
45
|
+ public static Dictionary<string, int> _Base64Code
|
|
|
46
|
+ {
|
|
|
47
|
+ get
|
|
|
48
|
+ {
|
|
|
49
|
+ return Enumerable.Range(0, Base64Code.Count()).ToDictionary(i => Base64Code[i], i => i);
|
|
|
50
|
+ }
|
|
|
51
|
+ }
|
|
|
52
|
+ }
|
|
|
53
|
+}
|