C# 十进制转换为任意进制
public string DtoStringByChars(int d)
{
string codeAllChar = "0123456789ABCDEFGHJKLMNPQRSTUVWXY";
char[] chrs = codeAllChar.ToCharArray();
int chrsLength = chrs.Length;
string x = "";
if (d < chrsLength)
{
x = chrs[d].ToString();
}
else
{
int c;
int s = 0;
int n = d;
int temp = d;
while (n >= chrsLength)
{
s++;
n = n / chrsLength;
}
string[] m = new string[s];
int i = 0;
do
{
c = d / chrsLength;
m[i++] = chrs[d % chrsLength].ToString();
d = c;
} while (c >= chrsLength);
x = chrs[d].ToString();
for (int j = m.Length - 1; j >= 0; j--)
{
x += m[j];
}
}
return x;
}
{
string codeAllChar = "0123456789ABCDEFGHJKLMNPQRSTUVWXY";
char[] chrs = codeAllChar.ToCharArray();
int chrsLength = chrs.Length;
string x = "";
if (d < chrsLength)
{
x = chrs[d].ToString();
}
else
{
int c;
int s = 0;
int n = d;
int temp = d;
while (n >= chrsLength)
{
s++;
n = n / chrsLength;
}
string[] m = new string[s];
int i = 0;
do
{
c = d / chrsLength;
m[i++] = chrs[d % chrsLength].ToString();
d = c;
} while (c >= chrsLength);
x = chrs[d].ToString();
for (int j = m.Length - 1; j >= 0; j--)
{
x += m[j];
}
}
return x;
}

浙公网安备 33010602011771号