This question already has an answer here:
-
How to convert numbers between hexadecimal and decimal
17 answers
Convert Hex to Decimal
Example:
It would ask a Hex. Shown below.
Enter Hex: 8000 8000 1000 0100
Then,
The Result: 32768 32768 4096 256
Convert each hex to decimal.
HEX = DECIMAL
8000 = 32768
8000 = 32768
1000 = 4096
0100 = 256
use string.split(' ') to get your individual hex-numbers as a string-array. Then you can call
int dec = int.Parse(hex, System.Globalization.NumberStyles.HexNumber);
to convert each hex into its decimal representation.
Console.Write("Enter HEX: ");
string hexValues = Console.ReadLine();
string[] hexValuesSplit = hexValues.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine("HEX = DECIMAL");
foreach (String hex in hexValuesSplit)
{
// Convert the number expressed in base-16 to an integer.
int value = Convert.ToInt32(hex, 16);
Console.WriteLine(string.Format("{0} = {1}", hex, Convert.ToDecimal(value)));
}
Console.ReadKey();
P.S. : The original code does not belong to me. For original codes please refer to MSDN