Binary integers

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

    #1

    Binary integers

    I've obviously got a blind spot for binary arithmetic! Why can't I
    say:

    Dim x as uint32 = &HFFFFFFFF

    (which gives a 'Constant expression not representable' error in
    VB2005)

    8 characters each of 4 bits should define a 32-bit integer, shouldn't
    they? What am I failing to spot/understand?

    Is this where integer literals come in - I've seen the term but not a
    description?

    Dim x as int32 = &HFFFFFFFFI

    seems to clear the error though not if it's still declared as a uint.
    Is this the recommended way to do what I'm trying to do? (Which is to
    define an ARGB colour, but not as a .Net colour type - the third-party
    DLL that I need to pass a value to doesn't work directly with .Net
    colours.)
  • Patrice

    #2
    Re: Binary integers

    Use the UI suffix to force an unsigned value (else this is a negative
    integer value that can't be used for an unsigned value).

    You could also use UInt32.MaxValue ...

    ---
    Patrice

    "John Dann" <news@prodata.c o.uka écrit dans le message de news:
    eo09a3lotqaa3e4 3earuajg0avs4r2 u2q1@4ax.com...
    I've obviously got a blind spot for binary arithmetic! Why can't I
    say:
    >
    Dim x as uint32 = &HFFFFFFFF
    >
    (which gives a 'Constant expression not representable' error in
    VB2005)
    >
    8 characters each of 4 bits should define a 32-bit integer, shouldn't
    they? What am I failing to spot/understand?
    >
    Is this where integer literals come in - I've seen the term but not a
    description?
    >
    Dim x as int32 = &HFFFFFFFFI
    >
    seems to clear the error though not if it's still declared as a uint.
    Is this the recommended way to do what I'm trying to do? (Which is to
    define an ARGB colour, but not as a .Net colour type - the third-party
    DLL that I need to pass a value to doesn't work directly with .Net
    colours.)

    Comment

    • Armin Zingler

      #3
      Re: Binary integers

      "John Dann" <news@prodata.c o.ukschrieb
      I've obviously got a blind spot for binary arithmetic! Why can't I
      say:
      >
      Dim x as uint32 = &HFFFFFFFF
      >
      (which gives a 'Constant expression not representable' error in
      VB2005)

      In addition to Patrice: The literal at the right is interpreted as an
      Integer (not unsigned integer). It's value is -1. -1 can not be stored in an
      UInt32. Therefore the exception.


      Armin

      Comment

      Working...