Wednesday, 20 August 2014

HEX to ASCII and ASCII to HEX Class - C#

Leave a Comment
This article shows you how to convert string to hexadecimal and vice versa.

HEX TO ASCII Class

 
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualBasic; // I'm using  this class for Hex Converion
namespace Hex_Converter
{
    public class HexConverter
    {
        public string Data_Hex_Asc(ref string Data)
        {
            string Data1 = "";
            string sData = "";
            while (Data.Length > 0)
            //first take two hex value using substring.
            //then  convert Hex value into ascii.
            //then convert ascii value into character.
            {
                Data1 = System.Convert.ToChar(System.Convert.ToUInt32(Data.Substring(0, 2), 16)).ToString();

                sData = sData + Data1;
                Data = Data.Substring(2, Data.Length - 2);
            }
            return sData;
        }

        public string Data_Asc_Hex(ref string Data)
        {
            //first take each charcter using substring.
            //then  convert character into ascii.
            //then convert ascii value into Hex Format

            string sValue;
            string sHex = "";
            while (Data.Length > 0)
            {
                sValue = Conversion.Hex(Strings.Asc(Data.Substring(0, 1).ToString()));
                Data = Data.Substring(1, Data.Length - 1);
                sHex = sHex + sValue;
            }

            return sHex;
        }
    }
}




By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.