In working with hexadecimal (strings stored in a database), integer and binary numeric representations, what is the difference between the folowwing 2 ways of converting from hexadecimal to integer:
List<string> hexadecimals = new List<string>
{
"A1F9",
"D",
"BF17D0015",
"972AB"
};
foreach(var hexadecimal in hexadecimals)
{
var i1 = Convert.ToInt64(hexadecimal, 16);
var i2 = Int64.Parse(hexadecimal, NumberStyles.HexNumber);
Console.WriteLine($"hexa: {hexadecimal}, converted: {i1}, parsed: {i2}. Are equal: [{i1.Equals(i2)}]");
}
- Convert.ToInt64(hexadecimal, 16);
- Int64.Parse(hexadecimal, NumberStyles.HexNumber);
Should I prefer one to another ?
Output: