I'm implementing a Skein hash function in Java, and I have a problem with a part where some additions where modulo 2^64. As I we know, long in java has max value = 2^63-1. So my problem is, how to implement this modulo operation. (All operations in Skein are on 64bit words.)
long
in Java is 64-bit so all operations are mod 2^64 already. You don't have to do anything extra to make that happen.
Is the problem that you don't know how to handle signed values?
Is this something you want or is it something you are trying to avoid?
BigInteger
is one way to do it.
In addition to Peter's answer, I want to suggest taking a look at the great Guava library. It has a class UnsignedLongs which offers several utility functions for working with longs treating them as unsigned. This might be helpful for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With