码迷,mamicode.com
首页 > 其他好文 > 详细

16进制编码解码

时间:2015-08-17 21:16:37      阅读:1599      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!