足力健后端,使用.netcore版本,合并1个项目使用

NumberConvert.cs 2.1KB

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