Hex String To Binary - CSharp System

CSharp examples for System:Hex

Description

Hex String To Binary

Demo Code


using System.Text;
using System.IO;/*from www .j av  a2 s . c om*/
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        public static byte[] HexStringToBinary(this string data)
        {
            var bytes = new List<byte>();
            for (var i = 0; i < data.Length; i += 2)
                bytes.Add(Byte.Parse(data.Substring(i, 2), NumberStyles.HexNumber));

            return bytes.ToArray();
        }
}

Related Tutorials