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

  • 相关阅读:
    R 包安装问题
    特征值分解与奇异值分解
    向量内积&外积
    hdu_3449(有依赖背包)
    Gene co-expression analysis for functional classification and gene–disease predictions
    MCMC & 贝叶斯
    继承(来自视频)
    面向对象 创建对象
    mongodb笔记(三)
    mongodb笔记(二)
  • 原文地址:https://www.cnblogs.com/chenli0513/p/1858064.html
Copyright © 2011-2022 走看看