Skip to content

Instantly share code, notes, and snippets.

@vdonchev
Last active August 29, 2015 14:23
Show Gist options
  • Save vdonchev/7e4fd69199f01a588f3f to your computer and use it in GitHub Desktop.
Save vdonchev/7e4fd69199f01a588f3f to your computer and use it in GitHub Desktop.
HexToDec
using System;
class HexadecimalToDecimalNumber
{
static void Main()
{
Console.Write("Insert a Hexadecimal number: ");
string hex = Console.ReadLine();
long dec = 0;
for (int i = 0, bit = hex.Length - 1; i < hex.Length; i++, bit--)
{
long curNum;
if ((hex[bit] - '7') >= 10)
{
curNum = hex[bit] - '7';
}
else
{
curNum = long.Parse(hex[bit].ToString());
}
dec += curNum * ((long)Math.Pow(16, i));
}
Console.WriteLine(dec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment