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

Ragas picture Ragas · Dec 3, 2018 · Viewed 11.4k times · Source

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.

Answer

lrn picture lrn · Dec 3, 2018

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.