This morning I created another function to convert something in other something.
This time this function convert Int Value to Hex Value and Hex Value to Int Value.
You find a demo at this link.
protected void CmdConvert1(object sender, EventArgs e)
{
//set the default value
uint uiDecimal = 0;
try
{
// Convert text string to integer
uiDecimal = Convert.ToUInt32(TxtText1.Text);
}
catch (OverflowException exception)
{
// Show overflow message and return
TxtHex1.Text = "Overflow";
return;
}
// Format hex value and show in another textbox
TxtHex1.Text = String.Format("{0:x2}", uiDecimal);
}
protected void CmdConvert2(object sender, EventArgs e)
{
uint uiHex = 0;
try
{
// Convert hex value to int
uiHex = Convert.ToUInt32(TxtHex2.Text, 16);
}
catch (OverflowException exception)
{
// Show overflow message and return
TxtText2.Text = "Overflow";
return;
}
// Format it and show as a string
TxtText2.Text = uiHex.ToString();
}