Convert the Hex string into Byte Array in C# with Sample



The following code changes the hexadecimal string to a byte array by parsing the string byte-by-byte.

 public static byte[] HexStringToByteArray(String hexString)
        {
            return Enumerable.Range(0, hexString.Length)
                    .Where(x => x % 2 == 0)
                    .Select(x => Convert.ToByte(hexString.Substring(x, 2), 16))
                    .ToArray();
        }

0 Comment's

Comment Form

Submit Comment