public static double BitOp(double d1, double d2, string op) { BitFunction f = BitFunction.AND; switch (op) { case "and": f = BitFunction.AND; break; case "or": f = BitFunction.OR; break; case "not": f = BitFunction.NOT; break; case "xor": f = BitFunction.XOR; break; case "shl": f = BitFunction.SHL; break; case "shr": f = BitFunction.SHR; break; } return(BitOps.DoFunction(d1, d2, f)); }
public void TestDefinitionBit() { var def = new BitFunction(); Assert.That(def.Name.Name, Is.EqualTo("bit")); Assert.That(def.Parameters.Count, Is.EqualTo(2)); Assert.That(def.Parameters.ElementAt(0).Name, Is.EqualTo("index")); Assert.That(def.Parameters.ElementAt(1).Name, Is.EqualTo("address")); }
public static double DoFunction(double p1, double p2, BitFunction function) { if (Floats(p1) || Floats(p2)) { throw new Exception("Binary operations only supported on integer types"); } else { var n1 = new BigInteger(p1); var n2 = new BigInteger(p2); BigInteger result = 0; switch (function) { case BitFunction.AND: result = n1 & n2; break; case BitFunction.OR: result = n1 | n2; break; case BitFunction.XOR: result = n1 ^ n2; break; case BitFunction.NOT: result = ~n1; break; case BitFunction.SHL: result = n1 << (int)n2; break; case BitFunction.SHR: result = n1 >> (int)n2; break; } return((double)result); } }