码迷,mamicode.com
首页 > Windows程序 > 详细

c#十进制转换

时间:2019-09-09 10:31:08      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:length   substr   return   head   param   int   str   方法   static   

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)

c#十进制转换

标签:length   substr   return   head   param   int   str   方法   static   

原文地址:https://www.cnblogs.com/ouyangkai/p/11490193.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!