Binary integers

J

John Dann

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.)
 
P

Patrice

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...
 
A

Armin Zingler

John Dann said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top