Hex To Byte Array - CSharp System

CSharp examples for System:Byte

Description

Hex To Byte Array

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Globalization;
using System;//ww w . ja  va  2 s .  co m

public class Main{
        public static byte[] HexToByteArray(this string input)
        {
            return Enumerable.Range(0, input.Length)
                             .Where(x => x%2 == 0)
                             .Select(x => Convert.ToByte(input.Substring(x, 2), 16))
                             .ToArray();
        }
}

Related Tutorials