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;
        }
posted @ 2011-08-26 11:32  星释天狼  阅读(252)  评论(0)    收藏  举报