GeekZilla
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);
Author Paul Hayman
Paul is the COO of kwiboo ltd and has more than 20 years 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; }