You are not Logged in
Would you like to Login or Register

Today is: 10 February 2012
Check this months hot topics

Convert to and from Hex

Convert from an int to Hex

String result = String.Format("{0:x2}", 255)

Convert from Hex to an int

int result = int.Parse("FF", System.Globalization.NumberStyles.HexNumber);
kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Paul Hayman Skype
Author : Paul Hayman
Published : 15 November 2006

Paul is the COO of kwiboo ltd consultant and has more than a decade of IT consultancy experience. He has consulted for a number of blue chip companies and has been exposed to the folowing sectors: Utilities, Telecommunications, Insurance, Media, Investment Banking, Leisure, Legal, CRM, Pharmaceuticals, Interactive Gaming, Mobile Communications, Online Services. Paul is the COO and co-founder of kwiboo (http://www.kwiboo.com/) and is also the creator of GeekZilla.

Comments

Andrew said:

Really good post. If you want to do the same with a string instead of an int try the below.

    public string ConvertToHex(string asciiString)    {        string hex = "";        foreach (char c in asciiString)        {            int tmp = c;            hex += String.Format("{0:x2}",                      (uint)System.Convert.ToUInt32(tmp.ToString()));        }        return hex;    }
November 04, 2008 - 2:41 PM

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views