+ /**
+ * Returns the value of the BitVector as BigInteger.
+ *
+ * @throws NumberFormatException if the BitVector is not {@link #isBinary() binary}.
+ */
+ public BigInteger getUnsignedValue()
+ {
+ if (!isBinary())
+ throw new NumberFormatException(this + " is not binary");
+ byte[] bytes = new byte[(bits.length / 8 + (bits.length % 8 == 0 ? 0 : 1)) + 1];
+ for (int i = bits.length - 1; i >= 0; i--)
+ {
+ if (Bit.ONE == bits[bits.length - i - 1])
+ {
+ try
+ {
+ bytes[bytes.length - (i / 8) - 1] |= 1 << (i % 8);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ return new BigInteger(bytes);
+ }
+