Fixed a bug in Am2900; created dlatch8/80; relayouted some components
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / types / BitVector.java
index 4d5f911..1346694 100644 (file)
@@ -437,6 +437,31 @@ public final class BitVector implements StrictLogicType<BitVector>, Iterable<Bit
                return new BigInteger(bytes);
        }
 
+       public long getUnsignedValueLong()
+       {
+               return getUnsignedValue().longValue();
+       }
+
+       /**
+        * Returns the value of the BitVector as BigInteger interpreted as a two's complement number.
+        * 
+        * @throws NumberFormatException if the BitVector is not {@link #isBinary() binary}.
+        * 
+        * @author Daniel Kirschten
+        */
+       public BigInteger getSignedValue()
+       {
+               BigInteger unsignedValue = getUnsignedValue();
+               if (bits[bits.length - 1] == Bit.ZERO)
+                       return unsignedValue;
+               return unsignedValue.subtract(BitVector.of(Bit.ONE, bits.length).getUnsignedValue()).subtract(BigInteger.ONE);// TODO speed this up!
+       }
+
+       public long getSignedValueLong()
+       {
+               return getSignedValue().longValue();
+       }
+
        /**
         * Parses a String containing solely {@link Bit} symbols (MSB first)
         * 
@@ -491,4 +516,15 @@ public final class BitVector implements StrictLogicType<BitVector>, Iterable<Bit
                        }
                };
        }
+
+       public BitVector reverse()
+       {
+               int length = length();
+               Bit[] other = new Bit[length];
+               for (int i = 0, j = length - 1; i < length; i++, j--)
+               {
+                       other[i] = bits[j];
+               }
+               return new BitVector(other);
+       }
 }