Program.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ShwasherSys.Test
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. //Console.WriteLine("");
  13. Console.WriteLine(Int10CalcTo32(32 * 32 * 32 * 32 - 2,5)); ;
  14. // Cal32ToInt10("ZZ");
  15. Console.ReadKey();
  16. }
  17. public static string Int10CalcTo32(int inputNum,int maxSize)
  18. {
  19. int max = 0;
  20. var result = new string[20];
  21. var displayArr = new string[]
  22. {
  23. "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M",
  24. "N", "P", "Q", "R", "T", "U", "V", "W", "X", "Y", "Z"
  25. };
  26. int ten = inputNum;
  27. int arrSize = displayArr.Length;
  28. string lResult = "";
  29. do
  30. {
  31. var sixteen = ten % arrSize;
  32. ten = ten / arrSize;
  33. result[max] = displayArr[sixteen];
  34. lResult = result[max]+ lResult;
  35. max++;
  36. } while (ten != 0);
  37. lResult = lResult.PadLeft(maxSize, '0');
  38. return lResult;
  39. }
  40. public static double Cal32ToInt10(string inputNum)
  41. {
  42. if (string.IsNullOrEmpty(inputNum))
  43. {
  44. return -1;
  45. }
  46. var displayStr = "0123456789ABCDEFGHJKMNPQRTUVWXYZ";
  47. int disLength = displayStr.ToArray().Length;
  48. double numResult = 0;
  49. var inputArr = inputNum.ToArray().Reverse().ToList();
  50. for (int i=0;i < inputArr.Count;i++)
  51. {
  52. int index = displayStr.IndexOf(inputArr[i]);
  53. if (index < 0)
  54. {
  55. return -1;
  56. }
  57. numResult += index* Math.Pow(disLength, i);
  58. }
  59. return numResult;
  60. }
  61. }
  62. }