问题:    0-9,a-z总共有36个字符,怎么把10进制转换成36进制,谁能给个方法???    谁能写个方法,能给出进制间的相互转换????

解决方案 »

  1.   

    嗯,比较简单,都是%36取余数,并且把余数往栈里面扔
    出栈输出的时候用case转换一下,从10开始
    switch(余数)
    case 10:
    输出 a.
    case 11:
    输出 b.
    ...
    case 35
    输出 z
      

  2.   

      private void button2_Click(object sender, EventArgs e)
            {
                int _Value = 35;            string _Text=ConvertToText(_Value, 36);
                       }        public string ConvertToText(long p_Value, int p_Numb)
            {
                List<char> _TestList = new List<char>();            char[] _CharList = new char[] { '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' };
                while (true)
                {
                    long _Index = p_Value % p_Numb;
                    p_Value = p_Value / p_Numb;
                    _TestList.Add(_CharList[_Index]);
                    if (p_Value == 0) break;
                }
                char[] _ReturnChar = _TestList.ToArray();
                Array.Reverse(_ReturnChar);
                return new string(_ReturnChar);
            }这样?
      

  3.   

            public static string Jin36(int i)
            {
                string s = "";
                int j = 0;
                while (i > 36)
                {
                    j = i % 36;
                    if (j <= 9) 
                        s += j.ToString();
                    else 
                        s += Convert.ToChar(j - 10 + 'a');
                    i = i / 36;
                }
                if (i <= 9) 
                    s += i.ToString();
                else 
                    s += Convert.ToChar(i - 10 + 'a');
                Char[] c = s.ToCharArray();
                Array.Reverse(c);
                return new string(c);
                
            }
      

  4.   

            public static string Jin36(int i)
            {
                string s = "";
                while (i > 36)
                {
                    int j = i % 36;
                    s += ((j <= 9) ? Convert.ToChar(j + '0') : Convert.ToChar(j - 10 + 'a'));
                    i = i / 36;
                }
                s += ((i <= 9) ? Convert.ToChar (i+'0') : Convert.ToChar(i-10+'a'));            Char[] c = s.ToCharArray();
                Array.Reverse(c);
                return new string(c);
            }
      

  5.   


            public static string C10_36(long i)
            {
                string s = "";
                int j = 0;
                while (i > 36)
                {
                    j = i % 36;
                    if (j < 10) 
                        s += j.ToString();
                    else 
                        s += Convert.ToChar(j + 87);
                    i = i \ 36;
                }
                if (i < 10) 
                    s += i.ToString();
                else 
                    s += Convert.ToChar(i + 87);
                Char[] c = s.ToCharArray();
                Array.Reverse(c);
                return new string(c);            
            }
      

  6.   

      NumberSystemUtil.ConvertDecimal(31, Scale.Hexadecimal);
    public class NumberSystemUtil
        { 
            public static void ConvertDecimal(int dec, Scale scale)
            {
                Stack<int> stack = new Stack<int>();            while (dec > 0)
                {
                    stack.Push(dec % (int)scale);
                    dec = dec / (int)scale;
                }            while (stack.Count > 0)
                {
                    if (scale == Scale.Hexadecimal)
                        Console.Write(stack.Pop().ToString("x"));
                    else
                        Console.Write(stack.Pop());
                }
            }
        }    public enum Scale
        {
            Hexadecimal = 16,
            Octal = 8,
            Binary = 2
        }
      

  7.   


    36进制转换10进制,假如说是abc= ((36*a+b)*36)+c 
    加减乘除运算和10进制一样,不同的是他是见36进1