Convert String To Byte array - CSharp System

CSharp examples for System:Byte Array

Description

Convert String To Byte array

Demo Code


using System.Text;
using System.IO;// ww  w.  j a v  a  2 s  .c om
using System.Globalization;
using System;

public class Main{
        public static byte[] ToBytes(this string hexString)
        {
            byte[] numArray = new byte[hexString.Length / 2];
            for (int index = 0; index < numArray.Length; ++index)
            {
                string s = hexString.Substring(index * 2, 2);
                numArray[index] = byte.Parse(s, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
            }
            return numArray;
        }
}

Related Tutorials