byte[] bytes和string转换

时间:2014-05-01 19:08:41   收藏:0   阅读:334

public static string ToHexString ( byte[] bytes ) // 0xae00cf => "AE00CF "
mamicode.com,码迷
        {
mamicode.com,码迷            
string hexString = string.Empty;
mamicode.com,码迷            
if ( bytes != null )
mamicode.com,码迷            
{
mamicode.com,码迷                StringBuilder strB 
= new StringBuilder ();
mamicode.com,码迷
mamicode.com,码迷                
for ( int i = 0; i < bytes.Length; i++ )
mamicode.com,码迷                
{
mamicode.com,码迷                    strB.Append ( bytes[i].ToString ( 
"X2" ) );
mamicode.com,码迷                }

mamicode.com,码迷                hexString 
= strB.ToString ();
mamicode.com,码迷            }

mamicode.com,码迷            
return hexString;
mamicode.com,码迷        }

byte[] bytes和string转换,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!