Interpret a negative number as unsigned with BigInteger
问题 Is it possible to parse a negative number into an unsigned value with Java's BigInteger ? So for instance, I'd to interpret -1 as FFFFFFFFFFFFFFFF . 回答1: If you are thinking of a two's complement, you must specify a working bit length. A Java long has 64 bits, but a BigInteger is not bounded. You could do something as this: // Two's complement reference: 2^n . // In this case, 2^64 (so as to emulate a unsigned long) private static final BigInteger TWO_COMPL_REF = BigInteger.ONE.shiftLeft(64);