Decodes base16 string to bytes. - CSharp System

CSharp examples for System:String Base

Description

Decodes base16 string to bytes.

Demo Code


using System.Security.Cryptography;
using System;// ww w  .  j a  v  a2s  .  c  o m

public class Main{
        /// <summary>
        /// Decodes base16 string to bytes.
        /// </summary>
        public static Byte[] Decode(String base16)
        {
            Byte[] bytes = new Byte[base16.Length / 2];
            for (Int32 i = 0; i < base16.Length; i += 2)
            {
                Byte value = (Byte)Convert.ToInt32(base16.Substring(i, 2), 16);
                bytes.SetValue(value, i / 2);
            }
            return bytes;
        }
}

Related Tutorials