public class Helper
{
public static string Bytes2Hex(byte[] bytes, int index, int count)
{
try
{
return BitConverter.ToString(bytes, index, count).Replace("-", String.Empty);
}
catch { }
return string.Empty;
}
public static string Bytes2Hex(byte[] bytes)
{
try
{
return BitConverter.ToString(bytes).Replace("-", String.Empty);
}
catch { }
return string.Empty;
}
public static byte[] Hex2Bytes(string hex, int index, int length)
{
return Hex2Bytes(hex.Substring(index, length));
}
public static byte[] Hex2Bytes(string hex)
{
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < bytes.Length; i++)
bytes[i] = Convert.ToByte(hex.Substring(2 * i, 2), 16);
return bytes;
}
}