This works nicely:
Public Const test As ULong = 1 << 30
This doesn't work nicely:
Public Const test As ULong = 1 << 31
It creates this error:
Constant expression not representable in type 'ULong'
How do I make it work?
This does work:
Public Const test As Long = 1 << 31
But I have to use ULong.
You cannot shift 1 << 31
with a Long datatype, so you get this error.
However, this is because 1
, as an integer literal, is treated as an Int32, which is the default integer literal.
You should work around this by defining this as:
Public Const test As ULong = 1UL << 30
Public Const test2 As ULong = 1UL << 31
The UL flag says to make the 1 an unsigned long. See Type characters for details.
Try the following:
Public Const test As ULong = 1UL << 31
You need to explicitly tell the compiler you are doing the operation on a ULong
.
The C# equivalent works:
public const ulong test = 1UL << 31;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With