HexNumber Issues

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bungle

    HexNumber Issues

    Hi,

    Would anyone be able to explain why I get a "Input string was not in a
    correct format" on the following bit of code in C#??

    public static int GENERIC_READ =
    int.Parse("0xH8 0000000",System .Globalization. NumberStyles.He xNumber,
    null);

    Thanks

    Dave Court

  • Hans Kesting

    #2
    Re: HexNumber Issues

    Hi,
    >
    Would anyone be able to explain why I get a "Input string was not in a
    correct format" on the following bit of code in C#??
    >
    public static int GENERIC_READ =
    int.Parse("0xH8 0000000",System .Globalization. NumberStyles.He xNumber,
    null);
    >
    Thanks
    >
    Dave Court
    You don't want the "0xH" prefix there, you already specify that it's a
    hexnumber.

    And why not use:
    public static uint GENERIC_READ = 0x80000000;

    (note: the compiler requires a Uint here)


    Hans Kesting


    Comment

    • bungle

      #3
      Re: HexNumber Issues

      Thanks Hans

      Really appreciate your help

      Regards

      Comment

      • Dave Sexton

        #4
        Re: HexNumber Issues

        Hi Dave,

        Because the documentation says, "Strings parsed with this style are not
        permitted to be prefixed with 0x".
        [System.Globaliz ation.NumberSty les.AllowHexSpe cifier]

        HexNumber incorporates the AllowHexSpecifi er flag in its value.

        The code works if you remove the "0xH" prefix.

        Hans mentioned in his response that the number is greater than what fits in a
        signed Int32. The Parse method won't throw an exception but you might not get
        the value you expect. Try uint and uint.Parse instead if that causes a
        problem for you.

        --
        Dave Sexton

        "bungle" <bungle@wizardb uy.comwrote in message
        news:1163412007 .567364.122970@ i42g2000cwa.goo glegroups.com.. .
        Hi,
        >
        Would anyone be able to explain why I get a "Input string was not in a
        correct format" on the following bit of code in C#??
        >
        public static int GENERIC_READ =
        int.Parse("0xH8 0000000",System .Globalization. NumberStyles.He xNumber,
        null);
        >
        Thanks
        >
        Dave Court
        >

        Comment

        Working...