Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 926
Ragas Avatar asked Dec 03 '18 07:12

Ragas


People also ask

Is unsigned int 64-bit?

A 64-bit signed integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). A 64-bit unsigned integer. It has a minimum value of 0 and a maximum value of (2^64)-1 (inclusive).

How do you define int in darts?

In the Dart programming language, an integer is represented by the int keyword. As we may know, integers include whole numbers (i.e., non-decimal positive and negative numbers). For every integer, four bytes are allocated in the memory.

Which operator is valid for the int class in Dart?

Division operator. Relational less than operator. Shift the bits of this integer to the left by shiftAmount .…


1 Answers

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.

like image 158
lrn Avatar answered Sep 24 '22 02:09

lrn