16进制编码与字符串的互相转化

Q:16进制编码与字符串的互相转化

A: 

string  ddd  =   " jinjazz路过 " ;

            
string  strHex  =  BitConverter.ToString(System.Text.Encoding.Default.GetBytes(ddd));

            Console.WriteLine(strHex);

            
string [] strChars = strHex.Split( ' - ' );
            
byte [] b  =   new   byte [strChars.Length];
            
for  ( int  i = 0 ;i < strChars.Length;i ++ )
            
{
                b[i] 
=  Convert.ToByte(strChars[i],  16 );
            }

            
string  ddd1  =  System.Text.Encoding.Default.GetString(b);
            Console.WriteLine(ddd1);
            
return ;
            
            
/*
            6A-69-6E-6A-61-7A-7A-C2-B7-B9-FD
            jinjazz路过
            
*/

你可能感兴趣的:(String,byte)