+ /**
+ * Returns the value of the BitVector as BigInteger either unsigned or as two-complement.
+ *
+ * @param signed if true and the BitVector represents a negative two-complement integer, an equivalent BigInteger is returned
+ * @return the value of this BitVector as BigInteger
+ *
+ */
+ public BigInteger toBigInteger(boolean signed)
+ {
+ if (!isBinary())
+ throw new NumberFormatException(this + " is not binary");
+ BigInteger val = new BigInteger(toString(), 2);
+ if (signed && bits[0] == Bit.ONE)
+ val = val.not().setBit(val.bitLength()).add(BigInteger.ONE);
+ return val;
+ }
+