Java Code Examples for java.math.BigInteger#not()
The following examples show how to use
java.math.BigInteger#not() .
These examples are extracted from open source projects.
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 Project: beanshell File: Operators.java License: Apache License 2.0 | 6 votes |
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 2
Source Project: tutorials File: BigIntegerDemoUnitTest.java License: MIT License | 6 votes |
@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 3
Source Project: ghidra File: OpBehaviorIntNegate.java License: Apache License 2.0 | 5 votes |
@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 4
Source Project: ghidra File: VarnodeContext.java License: Apache License 2.0 | 5 votes |
/** * 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 5
Source Project: ghidra File: VarnodeContext.java License: Apache License 2.0 | 5 votes |
/** * 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 6
Source Project: ghidra File: VarnodeContext.java License: Apache License 2.0 | 5 votes |
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 7
Source Project: j2objc File: BigIntegerNotTest.java License: Apache License 2.0 | 5 votes |
/** * 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 8
Source Project: j2objc File: BigIntegerNotTest.java License: Apache License 2.0 | 5 votes |
/** * 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 Project: j2objc File: BigIntegerNotTest.java License: Apache License 2.0 | 5 votes |
/** * 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 10
Source Project: j2objc File: BigIntegerNotTest.java License: Apache License 2.0 | 5 votes |
/** * 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 11
Source Project: j2objc File: BigIntegerNotTest.java License: Apache License 2.0 | 5 votes |
/** * 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 12
Source Project: j2objc File: BigIntegerTest.java License: Apache License 2.0 | 5 votes |
/** * @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 13
Source Project: IPAddress File: AddressItem.java License: Apache License 2.0 | 4 votes |
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 14
Source Project: tddl5 File: BigIntegerType.java License: Apache License 2.0 | 4 votes |
@Override public Object doBitNot(Object v1) { BigInteger i1 = convertFrom(v1); return i1.not(); }
Example 15
Source Project: tddl File: BigIntegerType.java License: Apache License 2.0 | 4 votes |
@Override public Object bitNot(Object v1) { BigInteger i1 = convertFrom(v1); return i1.not(); }
Example 16
Source Project: pitest File: BigIntegerMutatorTest.java License: Apache License 2.0 | 4 votes |
@Override BigInteger apply(BigInteger left, BigInteger right) { return left.not(); }
Example 17
Source Project: gravel File: LargeIntegerExtensions.java License: Apache License 2.0 | 4 votes |
public static BigInteger bitInvert(BigInteger receiver) { return receiver.not(); }
Example 18
Source Project: es6draft File: BigIntType.java License: MIT License | 2 votes |
/** * 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(); }