Java Code Examples for java.math.BigInteger#not()

The following examples show how to use java.math.BigInteger#not() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigIntegerDemoUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenBigIntegers_whenPerformingBitOperations_thenExpectedResult() {
    BigInteger i = new BigInteger("17");
    BigInteger j = new BigInteger("7");

    BigInteger and = i.and(j);
    BigInteger or = i.or(j);
    BigInteger not = j.not();
    BigInteger xor = i.xor(j);
    BigInteger andNot = i.andNot(j);
    BigInteger shiftLeft = i.shiftLeft(1);
    BigInteger shiftRight = i.shiftRight(1);

    assertEquals(new BigInteger("1"), and);
    assertEquals(new BigInteger("23"), or);
    assertEquals(new BigInteger("-8"), not);
    assertEquals(new BigInteger("22"), xor);
    assertEquals(new BigInteger("16"), andNot);
    assertEquals(new BigInteger("34"), shiftLeft);
    assertEquals(new BigInteger("8"), shiftRight);
}
 
Example 2
Source File: Operators.java    From beanshell with Apache License 2.0 6 votes vote down vote up
static BigInteger bigIntegerUnaryOperation(BigInteger operand, int kind)
{
    switch(kind)
    {
        case PLUS:
            return operand;
        case MINUS:
            return operand.negate();
        case TILDE:
            return operand.not();
        case INCR:
            return operand.add(BigInteger.ONE);
        case DECR:
            return operand.subtract(BigInteger.ONE);
    }
    throw new InterpreterError("bad big integer unaryOperation");
}
 
Example 3
Source File: BigIntegerNotTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Not for a positive number
 */
public void testNotPos() {
    byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
    int aSign = 1;
    byte rBytes[] = {-1, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -27, 116};
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    BigInteger result = aNumber.not();
    byte resBytes[] = new byte[rBytes.length];
    resBytes = result.toByteArray();
    for(int i = 0; i < resBytes.length; i++) {
        assertTrue(resBytes[i] == rBytes[i]);
    }
    assertEquals("incorrect sign", -1, result.signum());
}
 
Example 4
Source File: BigIntegerTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @tests java.math.BigInteger#not()
 */
public void test_not() {
	for (BigInteger[] element : booleanPairs) {
		BigInteger i1 = element[0];
		BigInteger res = i1.not();
		int len = i1.bitLength() + 66;
		for (int i = 0; i < len; i++) {
               assertTrue("not", !i1.testBit(i) == res.testBit(i));
           }
	}
}
 
Example 5
Source File: BigIntegerNotTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Not for a negative number
 */

public void testNotSpecialCase() {
    byte aBytes[] = {-1, -1, -1, -1};
    int aSign = 1;
    byte rBytes[] = {-1, 0, 0, 0, 0};
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    BigInteger result = aNumber.not();
    byte resBytes[] = new byte[rBytes.length];
    resBytes = result.toByteArray();
    for(int i = 0; i < resBytes.length; i++) {
        assertTrue(resBytes[i] == rBytes[i]);
    }
    assertEquals("incorrect sign", -1, result.signum());
}
 
Example 6
Source File: BigIntegerNotTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Not for a negative number
 */
public void testNotNeg() {
    byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
    int aSign = -1;
    byte rBytes[] = {0, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -118};
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    BigInteger result = aNumber.not();
    byte resBytes[] = new byte[rBytes.length];
    resBytes = result.toByteArray();
    for(int i = 0; i < resBytes.length; i++) {
        assertTrue(resBytes[i] == rBytes[i]);
    }
    assertEquals("incorrect sign", 1, result.signum());
}
 
Example 7
Source File: OpBehaviorIntNegate.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public BigInteger evaluateUnary(int sizeout, int sizein, BigInteger in1) {
	if (in1.signum() < 0) {
		throw new AssertException("Expected unsigned in value");
	}
	return in1.not();
}
 
Example 8
Source File: BigIntegerNotTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Not for ONE
 */
public void testNotOne() {
    byte rBytes[] = {-2};
    BigInteger aNumber = BigInteger.ONE;
    BigInteger result = aNumber.not();
    byte resBytes[] = new byte[rBytes.length];
    resBytes = result.toByteArray();
    for(int i = 0; i < resBytes.length; i++) {
        assertTrue(resBytes[i] == rBytes[i]);
    }
    assertEquals("incorrect sign", -1, result.signum());
}
 
Example 9
Source File: BigIntegerNotTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Not for ZERO 
 */
public void testNotZero() {
    byte rBytes[] = {-1};
    BigInteger aNumber = BigInteger.ZERO;
    BigInteger result = aNumber.not();
    byte resBytes[] = new byte[rBytes.length];
    resBytes = result.toByteArray();
    for(int i = 0; i < resBytes.length; i++) {
        assertTrue(resBytes[i] == rBytes[i]);
    }
    assertEquals("incorrect sign", -1, result.signum());
}
 
Example 10
Source File: VarnodeContext.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public void propogateValue(Register reg, Varnode node, Varnode val, Address address) {
	if (debug) {
		Msg.info(this, "   " + reg.getName() + "<-" + val.toString() + " at " +
			offsetContext.getAddress());
	}

	addSetVarnodeToLastSetLocations(node, address);

	offsetContext.setValue(reg, BigInteger.valueOf(val.getOffset()));

	// set lastSet for any children locations
	List<Register> childRegisters = reg.getChildRegisters();
	for (Register register : childRegisters) {
		if (register.getMinimumByteSize() >= program.getDefaultPointerSize()) {
			node = getRegisterVarnode(register);

			addSetVarnodeToLastSetLocations(node, address);
		}
	}

	// use zero for constants, so space will blend!
	BigInteger bigSpaceID = BigInteger.ZERO;
	if (!val.isConstant()) {
		int spaceID = val.getSpace();
		bigSpaceID = BigInteger.valueOf(spaceID);
	}
	//   Otherwise, invert so they won't blend
	bigSpaceID = bigSpaceID.not();  // only flip space bits that are non-zero
	spaceContext.setValue(reg, bigSpaceID);
}
 
Example 11
Source File: VarnodeContext.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * get the translated stored space value.
 * SpaceID is stored invert'ed so that the constants for subpieces will blend,
 * but no other space will.
 * 
 * @return null space for constant space, real spaceID otherwise.
 */
private BigInteger getTranslatedSpaceValue(Register reg, Address fromAddr, Address toAddr) {
	BigInteger spaceVal = spaceContext.getValue(reg, fromAddr, toAddr, true);
	if (spaceVal != null) {
		spaceVal = spaceVal.not();  // only flip space bits that are non-zero
	}
	if (spaceVal != null && BigInteger.ZERO.equals(spaceVal)) {
		return null;
	}
	return spaceVal;
}
 
Example 12
Source File: VarnodeContext.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * get the translated stored space value.
 * SpaceID is stored invert'ed so that the constants for subpieces will blend,
 * but no other space will.
 * 
 * @return null space for constant space, real spaceID otherwise.
 */
private BigInteger getTranslatedSpaceValue(Register reg) {
	BigInteger spaceVal = spaceContext.getValue(reg, true);
	if (spaceVal != null) {
		spaceVal = spaceVal.not();  // only flip space bits that are non-zero
	}
	if (spaceVal != null && BigInteger.ZERO.equals(spaceVal)) {
		return null;
	}
	return spaceVal;
}
 
Example 13
Source File: BigIntegerType.java    From tddl5 with Apache License 2.0 4 votes vote down vote up
@Override
public Object doBitNot(Object v1) {
    BigInteger i1 = convertFrom(v1);
    return i1.not();
}
 
Example 14
Source File: AddressItem.java    From IPAddress with Apache License 2.0 4 votes vote down vote up
static boolean testRange(BigInteger lowerValue, BigInteger upperValue, BigInteger finalUpperValue, int bitCount, int divisionPrefixLen) {
	BigInteger networkMask = AddressDivisionGroupingBase.ALL_ONES.shiftLeft(bitCount - divisionPrefixLen);
	BigInteger hostMask = networkMask.not();
	return testRange(lowerValue, upperValue, finalUpperValue, networkMask, hostMask);
}
 
Example 15
Source File: BigIntegerType.java    From tddl with Apache License 2.0 4 votes vote down vote up
@Override
public Object bitNot(Object v1) {
    BigInteger i1 = convertFrom(v1);
    return i1.not();
}
 
Example 16
Source File: BigIntegerMutatorTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
BigInteger apply(BigInteger left, BigInteger right) {
  return left.not();
}
 
Example 17
Source File: LargeIntegerExtensions.java    From gravel with Apache License 2.0 4 votes vote down vote up
public static BigInteger bitInvert(BigInteger receiver) {
	return receiver.not();
}
 
Example 18
Source File: BigIntType.java    From es6draft with MIT License 2 votes vote down vote up
/**
 * BigInt::bitwiseNOT (x)
 * 
 * @param x
 *            the BigInt value
 * @return the one's complement of {@code x}
 */
public static BigInteger bitwiseNOT(BigInteger x) {
    return x.not();
}