How to use BigInteger class to implement an unsigned 64 bit int in Java?

I'm looking for a data type with an exact capacity of 0 to 2 ^ 64 – 1 We know that Java does not support 'unsigned' restricted character data types

The BigInteger class allows you to create large numbers that cannot be supported by long data types But I don't know how the BigInteger class will serve my purpose The BigInteger class only allows allocation through constructors I see the following possibilities, but it will generate a random number

BigInteger(int numBits,Random rnd) 
Constructs a randomly generated BigInteger,uniformly distributed over the range 0 to (2^numBits - 1),inclusive.

I can't see any setValue (x) API, so I can choose my own value to this BigInteger How do you use the BigInteger class to achieve this, or are there other methods? Please mail a code example

PS: someone here released a problem without implementation details

Solution

You can often use Java's signed digital data types as if they were unsigned

See the old answer about Java signature and unsigned

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>