将16进制转化为10进制的方法

时间:2024-03-07 22:23:55

上次读IC卡的固有序列号,然后访问Oracle数据库,固有序列号是16进制的,在数据库中被转化为10进制卡号存储的,所以我需要将16进制转为10进制序列号进行传值,没有找到很简单的方法,就只有一下笨蛋法,尽供参考,哪位同仁若有更好的方法请多多指教:

 

public long check(string str)
        {
            char[] _qunece = str.ToCharArray();
            long sum = 0;
            int quan = 1;
            for (int i = 0; i < _qunece.Length; i++)
            {
                string ssss = _qunece[str.Length - i - 1].ToString();
                if (ssss == "a" || ssss == "A")
                    ssss = "10";
                if (ssss == "b" || ssss == "B")
                    ssss = "11";
                if (ssss == "c" || ssss == "C")
                    ssss = "12";
                if (ssss == "d" || ssss == "D")
                    ssss = "13";
                if (ssss == "e" || ssss == "E")
                    ssss = "14";
                if (ssss == "f" || ssss == "F")
                    ssss = "15";
                sum += Convert.ToInt16(ssss) * quan;
                quan = quan * 16;

            }
            return sum;
        }