首页 > 其他 > 详细

16进制编码解码

时间:2015-08-17 21:15:40      阅读:253      评论:0      收藏:0      [点我收藏+]
public string EncodingSMS(string s) 
        { 
            string result = string.Empty; 
 
            byte[] arrByte = System.Text.Encoding.GetEncoding("GB2312").GetBytes(s);     
            for(int i = 0; i < arrByte.Length; i++) 
            { 
                result += System.Convert.ToString(arrByte[i], 16);        //Convert.ToString(byte, 16)把byte转化成十六进制string 
            } 
 
            return result; 
        } 
 
        public string DecodingSMS(string s) 
        { 
            string result = string.Empty; 
 
            byte[] arrByte = new byte[s.Length / 2]; 
            int index = 0; 
            for(int i = 0; i < s.Length; i += 2) 
            { 
                arrByte[index++] = Convert.ToByte(s.Substring(i,2),16);        //Convert.ToByte(string,16)把十六进制string转化成byte 
            } 
            result = System.Text.Encoding.Default.GetString(arrByte); 
 
            return result; 
 
        }

16进制编码解码

原文:http://www.cnblogs.com/huangzhen22/p/4737517.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!