why this result is 0?

`dim v as UInt64 = 2^64-1`

why this result is 0?

`dim v as UInt64 = 2^64-1`

Try this:

` dim v as UInt64 = CType( 2, UInt64 ) ^ CType( 64, UInt64 ) - CType( 1, UInt64 )`

The types of the static values are determined by the compiler and are probably Integers (Int32 or Int64). You can be specific through CType or by assigning static values to typed constants or variables.

Maybe you should add that info into LR.

```
dim a as UInt64 = 2
dim b as UInt64 = 64
dim v2 as UInt64 = a^b-1
// has the same result with
dim v as UInt64 = CType( 2, UInt64 ) ^ CType( 64, UInt64 ) - CType( 1, UInt64 )
```

By “you”, I think you mean, “Xojo”. If you think that’s needed you should file a feature request through Feedback.

uh…

` dim v as UInt64 = CType( 2, UInt64 ) ^ CType( 64, UInt64 ) - CType( 1, UInt64 ) = 9223372036854775808`

but so does

`(2^63)-1`

so are you looking for (2^64)-1 or 2^(64-1)

because

2^64 (even as an interim value) exceeds Int64

and as UInt64 then (2^64)-1 is 18,446,744,073,709,551,615

meaning if I am correct, that Kems solution, while not giving a Zero value, still gives an incorrect one

[quote=296269:@Dave S]

so are you looking for (2^64)-1 or 2^(64-1)[/quote]

I was looking for maximum value of UInt32 UInt64, so (2^64)-1 is the correct one.

Theoretically, suppose 1 is also UInt64, then

```
UInt64 = (UInt64 ^ UInt64) - UInt64
= UInt64 - UInt64
= UInt64
```

So, ` (UInt64 ^ UInt64) = 2^64`

will exceed the maximum value.

Uh no… Max value of UINT32 is 4,294,967,295

the LangRef details all of this quite clearly

[quote=296274:@Dave S]Uh no… Max value of UINT32 is 4,294,967,295

the LangRef details all of this quite clearly[/quote]

Sorry typo. It’s UInt64

and the Max Value of UInt64 is NOT 9223372036854775808

it is (18,446,744,073,709,551,615)

As an aside, you can always use hex notation to remove all doubt. Just use a pair of “F” to represent each byte.

` dim v as UInt64 = &hFFFFFFFFFFFFFFFF`

or much more simply

dim u as Uint64 = -1

the rest is left as an exercise for the reader

Forum for Xojo Programming Language and IDE. Copyright © 2024 Xojo, Inc.