using System.Collections.Generic;
using System.Globalization;
public static class MyExtensionMethods
{
public static byte[] DecodeHex(this string text)
{
if (string.IsNullOrWhiteSpace(text))
{
return null;
}
List<byte> data = new List<byte>();
for (int i = 0; i < text.Length; i += 2)
{
string sub = text.Substring(i, 2);
data.Add((byte)int.Parse(sub, NumberStyles.HexNumber));
}
return data.ToArray();
}
}
Decode a hexadecimal string into an byte array.
See how to convert a byte array into a hexadecimal string here: https://codepad.co/snippet/5EgYVnol
See how to convert a byte array into a hexadecimal string here: https://codepad.co/snippet/5EgYVnol
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.