views:

73

answers:

2

I tried parsing a number with .NET Int64.Parse method, and it won't accept a string like "0x3039", even though that's how you write the constant in C#. The documentation specifically disallows the string to have a "0x" prefix, and a trailing "h" doesn't seem to work either.

To parse a hexadecimal number, I must have to use the System.Globalization.NumberStyles.HexNumber option.

If anyone knows off hand, for certain, that Int64.Parse() cannot accept strings with a "0x" prefix, please let me know.

+1  A: 

No, it won't accept 0x. There's even an AllowHexSpecifier option, but for some reason that just means the a-f digits and still expects you to strip of the 0x part.

Joel Coehoorn
AllowHexSpecifier is required to be able to distinguish between 1E3 being 483 in hex and being 1000 with the E indicating the beginning of the exponent.
Daniel Brückner
+5  A: 

The documentation gives the expressions for the supported number formats and accordingly neither prefixes nor postfixes are allowed for hexadecimal numbers.

Convert.ToInt32(String, Int32) supports the prefixes 0x and 0X when using base 16.

Daniel Brückner
Thanks for the quick answer! Just what I was looking for.
Triynko