{
Bit[] values = new Bit[bits];
for (int i = 0; i < bits; i++)
- {
values[bits - i - 1] = Bit.of(value.testBit(i));
- }
return new BitVector(values);
}
/**
* Does test for equality of values/content, shifting the other BitVector by <code>offset</code> to the right.<br>
- * Therefore <code>offset + other.length() <= this.length()</code> needs to be true.
+ * Therefore <code>offset + other.length() <= this.wdith()</code> needs to be true.
*
* @throws ArrayIndexOutOfBoundsException if <code>offset + other.length() > this.length()</code>
*
{
if (!isBinary())
throw new NumberFormatException(this + " is not binary");
- byte[] bytes = new byte[(bits.length / 8) + 1];
+ byte[] bytes = new byte[(bits.length / 8 + (bits.length % 8 == 0 ? 0 : 1)) + 1];
for (int i = 0; i < bits.length; i++)
{
if (Bit.ONE == bits[i])
{
- bytes[i / 8] |= 1 << (i % 8);
+ try
+ {
+ bytes[(i / 8) + 1] |= 1 << (i % 8);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ e.printStackTrace();
+ }
}
}
return new BigInteger(bytes);