Mutual conversion between C # byte array with hexadecimal

1.byte array to a hexadecimal string 16

/// <Summary> 
/// byte array will be converted into a hexadecimal character string 
/// </ Summary> 
/// <param name = "Data"> byte array </ param> 
/// <Returns> hexadecimal string formatted </ Returns> 
public static string ByteArrayToHexString (byte [] Data) 
{ 
    the StringBuilder the StringBuilder new new SB = (* data.length. 3); 
    the foreach (Data byte B in) 
    { 
        sb.append (the Convert. the ToString (B, 16) .PadLeft (2, '0')); 
    } 
    return sb.ToString () the ToUpper ();. 
}  

2.16 hexadecimal string byte array transfer

/// <Summary> 
/// converted into a hexadecimal character string byte array 
/// </ Summary> 
/// <param name = "hexstring"> 16 hexadecimal string </ param> 
/// < returns> byte array </ Returns> 
public static byte [] ByteArrayToHexString (String hexstring) 
{ 
    // the 16-ary keys converted into a byte array 
    var = byteArray the new new byte [hexString.Length / 2]; 
    for (var X = 0; X <byteArray.Length; X ++) 
    { 
        var I = Convert.ToInt32 (hexString.Substring (X * 2, 2), 16); 
        byteArray The [X] = (byte) I; 
    } 
    return byteArray The; 
}

 

Written in the last

  Which big brother If it is found there is leakage of the carelessness of the article or need to add more content, welcome message! ! !

 related suggestion:

 

Guess you like

Origin www.cnblogs.com/Marydon20170307/p/11423230.html