zoukankan      html  css  js  c++  java
  • 十六进制与十进制的相互转换 [ 原创create by lee ]

    /*
         *
         *        creater:create by lee
         *        fuction : use to number to hex
         *        date :2010-10-21
         *
         *
         */
        public class HexUtility
        {
            /// <summary>
            /// int类型转换成十六进制
            /// </summary>
            /// <param name="number"></param>
            /// <returns></returns>
            public  string ToHexSystem(int number)
            {
                byte[] result = BitConverter.GetBytes(number);
                string result1 = BitConverter.ToString(result);
                return result1;
            }
            /// <summary>
            /// int类型转换成十六进制
            /// </summary>
            /// <param name="number"></param>
            /// <returns></returns>
            public  string Tohex(int number)
            {
                int _aid = number;
                var hexChars = "0123456789ABCDEF";
                var _xaid = "";
                do
                {
                    var i = _aid % 16;
                    _aid = (_aid - i) / 16;
                    _xaid = hexChars[i] + _xaid;
                } while (_aid > 0);
                while (_xaid.Length < 8)
                {
                    _xaid = "0" + _xaid;
                }
                return _xaid;
            }

            /// <summary>
            /// 十六进制转换成int类型
            /// </summary>
            /// <param name="hex">0AFC9C1B</param>
            public int HexToNumber(string hex)
            {

               return  Convert.ToInt32(hex, 16);
            }
        }                    如果转载请注明来源 create by lee

  • 相关阅读:
    小结css2与css3的区别
    javascript变量的作用域
    javascript面向对象
    小结php中几种网页跳转
    foreach
    post与get,这两人到底神马区别??
    typescript遍历Map
    dataTable.js参数
    showModal()和show()的区别
    javascript中location.protocol、location.hostname和location.port
  • 原文地址:https://www.cnblogs.com/chenli0513/p/1858064.html
Copyright © 2011-2022 走看看