﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Bevan Arps commented on What the hell?! Hex number parsing</title><description>"0x" is a hex specifier with ancestry back into the deep mists of "C" history. It's related to "0" for base 8:  27 == 033 == 0x1B
  
  
I'm not sure where it came from, but Delphi's Object Pascal language used $ to prefix int constants.
  
  
Also, the W3C uses "#" in the CSS specification.
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment12</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment12</guid><pubDate>Fri, 07 May 2010 23:58:51 GMT</pubDate></item><item><title>Anon commented on What the hell?! Hex number parsing</title><description>I guess the "0x" is a text-editor "atrefact"? In reality, the hex number is 9F, not 0x9F.
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment11</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment11</guid><pubDate>Fri, 07 May 2010 16:52:30 GMT</pubDate></item><item><title>dave-ilsw commented on What the hell?! Hex number parsing</title><description>The .NET 4 page for the three-argument Int64.Parse method includes this additional tidbit following the Non-composite NumberStyles values table:
  
  
"If the NumberStyles.AllowHexSpecifier flag is used, s must be a hexadecimal value."
  
  
Source: 
[msdn.microsoft.com/.../8b520kdx%28v=VS.100%29.aspx](http://msdn.microsoft.com/en-us/library/8b520kdx%28v=VS.100%29.aspx)</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment10</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment10</guid><pubDate>Fri, 07 May 2010 01:26:12 GMT</pubDate></item><item><title>Dmitry commented on What the hell?! Hex number parsing</title><description>You do not need both, NumberStyles.AllowHexSpecifier and NumberStyles.HexNumber, values. NumberStyles.HexNumber equals to  AllowLeadingWhite | AllowTrailingWhite | AllowHexSpecifier. And I agree with everyone about the bad naming of the hex specifier.
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment9</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment9</guid><pubDate>Fri, 07 May 2010 00:58:33 GMT</pubDate></item><item><title>Jakob Andersen commented on What the hell?! Hex number parsing</title><description>Ayende, 
  
As i remember: it isn't AllowHexSpecieir that makes the 0x prefix fail, i have never found a way to have long.Parse accept the prefix so i have used:
  
  
Convert.ToInt64("0x9f", 16);
  
  
Which is the same i asume you ended up with.  But i agree with you, the naming of AllowHexSpecifier is REALLY confusing.
  
  
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment8</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment8</guid><pubDate>Fri, 07 May 2010 00:43:10 GMT</pubDate></item><item><title>Thomas Krause commented on What the hell?! Hex number parsing</title><description>I think AllowHexSpecifier is horribly named. But the documentation is quite clear:
  
  
The s parameter contains a number of the form: 
  
[ws][sign]digits[ws] 
  
  
Or, if style includes AllowHexSpecifier:
  
[ws]hexdigits[ws]
  
...
  
hexdigits 
  
A sequence of hexadecimal digits from 0 through f, or 0 through F. 
  
  
AllowHexSpecifier tells Parse to treat the number as hexadecimal. HexNumber does the same, but also allows Whitespace before/after.
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment7</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment7</guid><pubDate>Fri, 07 May 2010 00:35:38 GMT</pubDate></item><item><title>Demis Bellot commented on What the hell?! Hex number parsing</title><description>Are you reading these docs?
  
[msdn.microsoft.com/.../...obalization.numberstyles](http://msdn.microsoft.com/en-us/library/system.globalization.numberstyles)(VS.80).aspx
  
  
Although its contra-intuitive (wouldn't be the first time) it says:
  
"AllowHexSpecifier -	Indicates that the numeric string represents a hexadecimal value. Valid hexadecimal values include the numeric digits 0-9 and the hexadecimal digits A-F and a-f. Hexadecimal values can be left-padded with zeros. Strings parsed using this style are not permitted to be prefixed with "0x". "
  
  
Normally in these situations I support the right behaviour by wrapping it in a 'int FromHex(this string)' extension method and move on until a better solution crosses my path.
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment6</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment6</guid><pubDate>Fri, 07 May 2010 00:34:57 GMT</pubDate></item><item><title>Ayende Rahien commented on What the hell?! Hex number parsing</title><description>Uncle Festis &amp; Demis,
  
I don't _want_ to drop that.
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment5</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment5</guid><pubDate>Fri, 07 May 2010 00:23:02 GMT</pubDate></item><item><title>Ayende Rahien commented on What the hell?! Hex number parsing</title><description>  
Jakob,
  
Thanks, I missed the not.
  
But What is up with _Allow_HexSpecifier, the only hex specifier that _I_ know of is 0x
  
And removing that from the bit pattern doesn't help: NumberStyles.HexNumber &amp; ~NumberStyles.AllowHexSpecifier
  
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment4</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment4</guid><pubDate>Fri, 07 May 2010 00:22:39 GMT</pubDate></item><item><title>Demis Bellot commented on What the hell?! Hex number parsing</title><description>Oren, dropping the '0x' prefix should work, e.g:
  
  
long.Parse("9f", NumberStyles.HexNumber)
  
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment3</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment3</guid><pubDate>Fri, 07 May 2010 00:11:23 GMT</pubDate></item><item><title>Jakob Andersen commented on What the hell?! Hex number parsing</title><description>From the documentation of NumberStyle.AllowHexSpecifier
  
  
'Strings parsed using this style are not permitted to be prefixed with "0x".'
  
  
btw. NumberStyles.HexNumber includes AllowHexSpecifier already.
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment2</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment2</guid><pubDate>Fri, 07 May 2010 00:11:11 GMT</pubDate></item><item><title>Uncle Festis commented on What the hell?! Hex number parsing</title><description>It no likey the "0x" at the beginning?
</description><link>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment1</link><guid>http://ayende.com/4489/what-the-hell-hex-number-parsing#comment1</guid><pubDate>Fri, 07 May 2010 00:10:55 GMT</pubDate></item></channel></rss>