Click here to Skip to main content
Licence 
First Posted 18 Jun 2003
Views 207,810
Bookmarked 31 times

Hex Converter

By | 18 Jun 2003 | Article
This article is about a program which helps you convert numeric value from decimal to hexadecimal representation and vice versa.

Introduction

This article is about how you would go about converting numeric values to hexadecimal and vice versa. The main reason why I did this program is to help me to cheat when playing computer games, mainly role-playing ones cos I normally need to find the correct hex data in those save game file and furthermore I do not have a good hex editor to help me do those conversion. :)

Using the code

The main code used for the conversion are from the System.Convert class. Below is the code that is used to convert a string to unsigned integer while checking for overflow, and then convert it to hexadecimal format before showing it as a string in a text box.

// To hold our converted unsigned integer32 value
uint uiDecimal = 0;

try
{
    // Convert text string to unsigned integer
    uiDecimal = checked((uint)System.Convert.ToUInt32(tbDecimal.Text));
}

catch (System.OverflowException exception) 
{
    // Show overflow message and return
    tbHex.Text = "Overflow";
    return;
}

// Format unsigned integer value to hex and show in another textbox
tbHex.Text = String.Format("{0:x2}", uiDecimal);

and vice versa

// To hold our converted unsigned integer32 value
uint uiHex = 0;

try
{
    // Convert hex string to unsigned integer
    uiHex = System.Convert.ToUInt32(tbHex.Text, 16);
}

catch (System.OverflowException exception) 
{
    // Show overflow message and return
    tbDecimal.Text = "Overflow";
    return;
}

// Format it and show as a string
tbDecimal.Text = uiHex.ToString();

Conclusion

This is my first attempt at C# and WinForms so I believe by starting with such simple and small programs, it will eventually build up my skills and knowledge to attempt bigger ones. :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Weiye Chen

Other

Singapore Singapore

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGood Work !!! Pinmemberdnpro21:15 28 Jan '09  
Generali'll write an article too!! PinmemberSeishin#23:46 7 Apr '08  
GeneralCool!! PinmemberMuammar©22:22 8 Apr '07  
You really have cool articles with cool ideas..
 

Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)

GeneralThanks PinmemberLaurent Cozic8:11 10 Oct '06  
GeneralFile to Hex Pinmemberchirag parikh20:21 4 May '06  
GeneralGood Work PinmemberSaqib Mehmood2:28 8 Aug '05  
GeneralHex To Text Pinmemberhmm214:33 11 Feb '05  
GeneralRe: Hex To Text PinmemberWeiye Chen16:13 11 Feb '05  
GeneralCould do this with Windows Calculator. Pinmemberred_tomato8:12 14 May '04  
GeneralRe: Could do this with Windows Calculator. PinmemberWeiye Chen16:41 14 May '04  
GeneralSuggestion Pinmemberleppie8:11 19 Jun '03  
GeneralRe: Suggestion PinmemberWeiye Chen16:44 19 Jun '03  
GeneralRingtone Convert to Hexcode (SMS) Pinsussliewwp0:28 3 Dec '04  
GeneralRe: Ringtone Convert to Hexcode (SMS) PinmemberWeiye Chen1:40 3 Dec '04  
GeneralRe: Ringtone Convert to Hexcode (SMS) Pinsusswpliew1:12 4 Dec '04  
GeneralRe: Ringtone Convert to Hexcode (SMS) PinmemberWeiye Chen16:25 4 Dec '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 19 Jun 2003
Article Copyright 2003 by Weiye Chen
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid