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

  • 相关阅读:
    问题14:如何拆分含有多种分隔符的字符串
    问题15:如何判断字符串a是否以字符串b开头或结尾
    问题16:如何调整字符串中文本的格式
    第三方支付公司之快钱
    js实现回调功能实例
    oracle查看未提交事务
    Tomcat错误之java.lang.OutOfMemoryError:PermGen space解决方案
    oracle错误之未知的命令开头imp忽略了剩余行解决方案
    修改easyui日期控件只显示年月,并且只能选择年月
    数据库三范式大总结
  • 原文地址:https://www.cnblogs.com/chenli0513/p/1858064.html
Copyright © 2011-2022 走看看