From Hex String to byte array - CSharp System

CSharp examples for System:Byte Array

Description

From Hex String to byte array

Demo Code


using System.Linq;
using System;//from   ww  w. j  a  v a 2s  .  c o m

public class Main{
        public static byte[] FromHexString(string hex)
        {
            var bytes = new byte[hex.Length / 2];
            for (int i = 0; i < hex.Length; i += 2)
            {
                bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
            }
            return bytes;
        }
}

Related Tutorials