views:

6816

answers:

5

In C++, I enjoyed having access to a 64 bit unsigned integer, via unsigned long long int, or via uint64_t. Now, in Java longs are 64 bits, I know. However, they are signed.

Is there an unsigned long (long) available as a Java primitive? How do I use it?

+4  A: 

I don't believe so. Once you want to go bigger than a signed long, I think BigInteger is the only (out of the box) way to go.

Sean Bright
+2  A: 

No, there isn't. The designers of Java are on record as saying they didn't like unsigned ints. Use a BigInteger instead. See this question for details.

Paul Tomblin
I respect Gosling for what he's done, but I think his defense of no unsigned ints is one of the dumbest excuses I've ever heard. :-) We've got waaaay more wonky things in Java than unsigned ints... :-)
Brian Knoblauch
Gosling at JavaPolis 2007 gave an example that confusingly doesn't work for unsigned ints. Josh Bloch pointed out it doesn't work for signed ints either. Arbitrary sized integers ftw!
Tom Hawtin - tackline
I don't respect Gosling for what he has done. To say that people don't understand unsigned math? It's signed math that is complex, especially at the bit level. I don't understand why people love Java when it was clearly written for stupid people (maybe it's computer science's most subtle joke?).
PP
+3  A: 

Nope, there is not. You'll have to use the primitive long data type and deal with signedness issues, or use a class such as BigInteger.

Adam Rosenfield
+1  A: 

Java does not have unsigned types. As already mentioned, incure the overhead of BigInteger or use JNI to access native code.

basszero
char is an unsigned 16-bit value ;)
Peter Lawrey
ARGH! You got me there. Well done my friend
basszero
+1  A: 

Depending on the operations you intend to perform, the outcome is much the same, signed or unsigned. However, unless you are using trivial operations you will end up using BigInteger.

Peter Lawrey