Last active
August 29, 2015 14:23
-
-
Save vdonchev/7e4fd69199f01a588f3f to your computer and use it in GitHub Desktop.
HexToDec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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