The Six Phases of a Project: Enthusiasm. Disillusionment. Panic. Search for the Guilty. Punishment of the Innocent. Praise for non-participants
Welcome to my blog about software development and the Microsoft stack.

I've been a full time .NET developer for ten years, but I didn't start my professional life as a programmer ... more
Share/Print this page:

Subscribe for news, updates and more:

Hexadecimal (Hex) to Decimal Lookup Table

Easily convert hex to decimal and back again with this convenient table

By steve on January 07, 2007.
Updated on January 22, 2012.
Viewed 149,214 times (128 times today).
Article TypesArticle TypesLanguagesTechnologiesTopics
ReferenceSnippetC#.NETWeb Design

C# Code to General Hex to Decimal Lookup Table

Contents

Following 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

Contents
public 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 we're beginning a new multiple of 16
      {
         if (i != 0) // if it's not the first multiple of 16
            sb.Append("</table cellpadding=4 cellspacing=0></td>");
         if ( i%64 == 0) // if we're beginning a new multiple of 64
         {
            if (i != 0) // if it's not the first multiple of 64
               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

User Comments (7)

Posted 2010 Jul 25 02:38 AM. reply
You are the greatest, I had the exact same problem, I did a little research and on the first link I clicked was this page with your table.

Charlie
Posted 2010 Oct 21 10:57 AM. reply
Great! thanks for sharing this.

Adam J. Mendoza
Posted 2011 Sep 28 13:44 PM. reply
This is also a great resource for looking up hex address number values. I'm currently studying IPv6 Addressing and that's how I came across this resource.

Thank you!

thirdeye
Posted 2012 Jan 12 04:36 AM. reply
Thanks bro, I needed a table to study because I am trainning to take my Network+ exam. I needed a way to look up BD in Hex cause I am learning IPv6. I really appreciate the help, thanks. Also to learn programming, do you have to be a math wiz? I am asking because I am actually thinking about becoming a programmer instead of computer tech. Thanks again and have a good day!

Darrell
Posted 2012 Jan 21 11:44 AM. reply
I LIKE THIS PORTION VERY MUCH SIR/MADAM THANKS VERY VERY THANKS

yasin
Posted 2012 Jan 24 17:07 PM. reply
Thanks a lot! It would be great too if you had the decimal normalized to 1 (a lot of programming languages use a 0-1 scale instead of 0 - 255). Three columns instead of just two? Thanks,

Spencer
Posted 2012 Feb 08 04:31 AM. reply
how do you covert hexardecimal to decimal

nikeel
Post Your Comment
  You may post without logging in or login here.
Display Name: Required.
Email: Required. Will not be shown. Used for identicon.
Comment:
Allowed tags: <quote></quote>, <code></code>, <b></b>, <i></i>, <u></u>, <red></red>
 
   Please type text as shown in the image at left.