takanoha
takanoha

Reputation: 353

Why can't UInt64 variable contain a value larger than UInt32::Max?

I have two variables a and b and are declared and assigned as follows:

UInt64 a = (UInt64)4294967295 * 3;
UInt64 b = 4294967295 * 3;

When I print them a contains 12884901885 and b contains 4294967295.

Why do I have to cast the number with UInt64 to store such a large value ?

Thanks

Upvotes: 0

Views: 231

Answers (1)

robthebloke
robthebloke

Reputation: 9682

you need to append 'ULL' (a.k.a. Unsigned Long Long) to the constant to indicate it should be considered to be a 64bit value.

UInt64 b = 4294967295ULL * 3;

Upvotes: 1

Related Questions