天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//十进制与其他进制转换通用函数 nhg2020-04-28
namespace QMAPP.FJC.DAL.BZD
{
static class DecimalToCharX
{
private static char[] ASCList = {'0','1', '2', '3', '4', '5', '6', '7', '8', '9',
'A','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$',
'/', '+', '%', '#', '&', '*', '=' };
//改写10进制转43进制函数
public static String decimalToCharX(int decimalValue,int toX)
{
String Char43 = "";
int hexValue;
while (decimalValue != 0)
{
hexValue = decimalValue % toX;
Char43 = ASCList[hexValue] + Char43;
decimalValue = decimalValue / toX;
}
if (Char43 == "")
{
Char43 = "0";
}
return Char43;
}
////将的十进制数转换成ASCList的43进制数
//public static char to43Char(int hexValue)
//{
// return ASCList[hexValue];
// //if (hexValue <= 9 && hexValue >= 0)
// //return (char)(hexValue + '0');
// //else
// //return (char)(hexValue - 10 + 'A');
//}
//将43进制数转换成10进制
public static int CharXTodecimal(string str,int toX)
{
int intDecimal = 0;
char[] charList = str.ToCharArray();
int dec = 0;
int digit = 0;
for (int i = charList.Length; i > 0; i--)
{
dec = ASCList.ToList().IndexOf(charList[i - 1]);
for (int j = 0; j < digit; j++)
{
dec = dec * toX;
}
intDecimal = intDecimal + dec;
digit++;
}
return intDecimal;
}
}
}