zoukankan      html  css  js  c++  java
  • 进制转换

    /// <summary>
        /// 进制转化
        /// </summary>
        public class JZZH
        {
            string SeedStr = "";
            int SeedLen = 0;
    
            /// <summary>
            /// 默认36进制
            /// </summary>
            /// <param name="seed"></param>
            public JZZH(string seed = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
            {
                SeedStr = seed;
                SeedLen = SeedStr.Length;
            }
            
            /// <summary>
            /// 编码
            /// </summary>
            /// <param name="val"></param>
            /// <returns></returns>
            public string Encode(int val)
            {
                string result = "";
                while (val >= SeedLen)
                {
                    result = SeedStr[val % SeedLen] + result;
                    val /= SeedLen;
                }
                if (val >= 0) result = SeedStr[val] + result;
                return result;
            }
    
            /// <summary>
            /// 解码
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public int Decode(string str)
            {
                int result = 0;
                int len = str.Length;
                for (int i = len; i > 0; i--)
                {
                    result += SeedStr.IndexOf(str[i - 1]) * Convert.ToInt32(Math.Pow(SeedLen, len - i));
                }
                return result;
            }
        }
  • 相关阅读:
    poj1330 Nearest Common Ancestors
    poj3237 Tree
    spoj2798 QTREE3 Query on a tree again!
    spoj913 QTREE2 Query on a treeⅡ
    自动类型转换
    js "+"连接符号
    js parseFloat
    js字符串与数字的运算
    js prompt
    js数组排序
  • 原文地址:https://www.cnblogs.com/jiang_zheng/p/6187199.html
Copyright © 2011-2022 走看看