Hex String To Byte Array - CSharp System

CSharp examples for System:Hex

Description

Hex String To Byte Array

Demo Code


using System.Drawing.Imaging;
using System.Drawing;
using System.IO;/* w  w w .j a  va 2  s .co m*/
using System.Security.Cryptography;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{
        public static byte[] HexStringToByteArray(string charset)
        {
            charset = charset.Replace(" ", "");

            byte[] buffer = new byte[charset.Length / 2];

            for (int i = 0; i < charset.Length; i += 2)
            {
                buffer[i / 2] = (byte)Convert.ToByte(charset.Substring(i, 2), 16);
            }

            return buffer;
        }
}

Related Tutorials