We know that the maximum value of Integer is 2^31 - 1, and the maximum value of Long is 2^63 - 1
This is true whether it is a 32-bit or a 64-bit machine
Generally speaking, when we want to operate a number greater than the maximum value of Integer, we will use Long to perform it.
But what if we encounter a number that is larger than the maximum value of Long?
BigInteger
This situation will still occur. Java provides a BigInteger class for operating extremely large numbers. When using it, you need to instantiate a BigInteger object, call its operation method for addition and subtraction.
Here is an example to illustrate
Operation UUID
We know that anroid_id is often used in Android devices to represent the uniqueness of the device
Generally, the following code will be called to generate a device number for the first time after installing the app.
String private_id = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
Then strings are stored in the file system or database through persistence, and indicators such as daily active users can be identified based on this.
Its value is usually a hexadecimal number, for example
AF84C9117B6C98D2
Convert it to decimal is
12647454730485537000
This has exceeded the range of Long maximum value 9223372036854776000
Then we want to simply encrypt it based on the original android_id, such as adding a random number to go up.
String private_id = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID);BigInteger androidId = new BigInteger(private_id, 16);Random random = new Random();BigInteger result = androidId.add(new BigInteger(String.valueOf(random.nextInt(10000)), 10));String hex = result.toString();