Quote:
|
Originally Posted by Ravatar
Code:
public static int ConvertHexToDecimal(string hexNumber)
{
if (hexNumber.IndexOf("0x") != -1)
hexNumber = hexNumber.Substring(2, hexNumber.Length - 2);
return Int32.Parse(hexNumber, System.Globalization.NumberStyles.AllowHexSpecifier);
}
|
Not a biggie, but the above code snippet I believe makes two assumptions (I do not profess to be versed in C#).
1. That the 0x occurs at the very beggining of the string. That there is no other whitespace in the string leading up to it. To address, one would adjust the Substring() call to use the index returned by the IndexOf() call.
2. It also assumes that one will never enter 0X instead of 0x.
These assumptions are probably valid 99% of the time, so I am sure one is probably making fine making these assumptions.