C# Code to General Hex to Decimal Lookup Table
ContentsFollowing is the C# code I wrote to generate the hexadecimal to decimal lookup table found on page 1.
Add the method to the code-behind page of an ASPX page. Be sure to add a Label named lblOutput and don't forget 'using System.Text' because I use the StringBuilder class to speed things up a bit.
(Obviously, you can adapt this for Windows Forms or console application, etc...)
C# Method. Generate Decimal to Hexadecimal Lookup Table
Contentspublic void GenerateHexDecConversionTable()
{
StringBuilder sb = new StringBuilder();
sb.Append("<table cellpadding=15 cellspacing=0 "
+ "border=1 border-color=gainsboro>");
for (int i=0; i<256; i++)
{
if ( i%(16) == 0)
{
if (i != 0)
sb.Append("</table cellpadding=4 cellspacing=0></td>");
if ( i%64 == 0)
{
if (i != 0)
sb.Append("</tr>");
sb.Append("<tr>");
}
sb.Append("<td align=center><table>");
sb.Append("<tr><td colspan=2><B>D: </b>"
+ i.ToString() + "-" + (i+15).ToString()
+ "</td></tr>");
sb.Append("<tr><td colspan=2><b>X: </b>"
+ i.ToString("X") + "-" + (i+15).ToString("X")
+ "</td></tr>");
sb.Append("<tr><td align=center><b>Dec</b></td>"
+ "<td><b>Hex</b></td></tr>");
}
if (i%2 == 0)
{
sb.Append("<tr><td align=center "
+ "style='font-weight:bold;background-color:black;color:white;'>"
+ i.ToString() + "</td><td align=center "
+ "style='font-weight:bold;background-color:white;color:black;'>"
+ i.ToString("X") + "</td></tr>");
}
else
{
sb.Append("<tr><td align=center "
+ "style="
+ "'font-weight:bold;background-color:dimgray;color:white;'>"
+ i.ToString() + "</td><td align=center "
+ "style="
+ "'font-weight:bold;background-color:gainsboro;color:black;'>"
+ i.ToString("X") + "</td></tr>");
}
}
sb.Append("</table></td></tr>");
sb.Append("</table>");
lblOutput.Text = sb.ToString();
} Back to Top