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

    1.方法定义

    /// <summary>
            /// 十进制转换
            /// </summary>
            /// <param name="hexChar"></param>
            /// <returns></returns>
            public static int HexChar2Value(string hexChar)
            {
                switch (hexChar)
                {
                    case "0":
                    case "1":
                    case "2":
                    case "3":
                    case "4":
                    case "5":
                    case "6":
                    case "7":
                    case "8":
                    case "9":
                        return Convert.ToInt32(hexChar);
                    case "a":
                    case "A":
                        return 10;
                    case "b":
                    case "B":
                        return 11;
                    case "c":
                    case "C":
                        return 12;
                    case "d":
                    case "D":
                        return 13;
                    case "e":
                    case "E":
                        return 14;
                    case "f":
                    case "F":
                        return 15;
                    default:
                        return 0;
                }
            }

     public int Hex2Ten(string hex)
            {
                int ten = 0;
                for (int i = 0, j = hex.Length - 1; i < hex.Length; i++)
                {
                    ten += HexChar2Value(hex.Substring(i, 1)) * ((int)Math.Pow(16, j));
                    j--;
                }
                return ten;
            }
    
    
    
    
    


    2.方法调用 (ushort)con.Hex2Ten(con.headset_vid), (ushort)con.Hex2Ten(con.headset_pid)

  • 相关阅读:
    noi 1944 吃糖果
    noi 6049 买书
    noi 2985 数字组合
    noi 2728 摘花生
    noi 2718 移动路线
    noi 4977 怪盗基德的滑翔翼
    noi 8780 拦截导弹
    noi 1996 登山
    NOI 动态规划题集
    图的色数
  • 原文地址:https://www.cnblogs.com/ouyangkai/p/11490193.html
Copyright © 2011-2022 走看看