Ragas
Ragas

Reputation: 3205

How do I declare 64bit unsigned int in dart/flutter?

For an app, I need a 64bit unsigned int. Looking at dart documentation I did not see how to exactly go about declaring one.

Can anyone tell me how this is done? I will use this "64bit unsigned int" in bitwise operation.

Upvotes: 30

Views: 23424

Answers (2)

Franci
Franci

Reputation: 2247

Just use fixnum

You can easily create an int64 with Int64()

Upvotes: 5

lrn
lrn

Reputation: 71603

Dart does not have a native unsigned 64-bit integer.

For many operations, you can just use the signed 64-bit integer that an int is, and interpret it as unsigned. It's the same bits. That won't work with division, though. (And if it's for the web, then an int is a JavaScript number, and you need to do something completely different).

The simplest general approach is to use a BigInt and use toUnsigned(64) after you do any operations on it.

Upvotes: 31

Related Questions