Java Code Examples for java.math.BigInteger#andNot()
The following examples show how to use
java.math.BigInteger#andNot() .
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: j2objc File: BigIntegerNotTest.java License: Apache License 2.0 | 6 votes |
/** * andNot for two positive numbers; the first is longer */ public void testAndNotPosPosFirstLonger() { byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23, 87, -25, -75}; byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23}; int aSign = 1; int bSign = 1; byte rBytes[] = {0, -128, 9, 56, 100, 0, 0, 1, 1, 90, 1, -32, 0, 10, -126, 21, 82, -31, -96}; BigInteger aNumber = new BigInteger(aSign, aBytes); BigInteger bNumber = new BigInteger(bSign, bBytes); BigInteger result = aNumber.andNot(bNumber); 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 2
Source Project: j2objc File: BigIntegerNotTest.java License: Apache License 2.0 | 6 votes |
/** * andNot for two positive numbers; the first is shorter */ public void testAndNotPosPosFirstShorter() { byte aBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23}; byte bBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23, 87, -25, -75}; int aSign = 1; int bSign = 1; byte rBytes[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 2}; BigInteger aNumber = new BigInteger(aSign, aBytes); BigInteger bNumber = new BigInteger(bSign, bBytes); BigInteger result = aNumber.andNot(bNumber); 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 3
Source Project: j2objc File: BigIntegerNotTest.java License: Apache License 2.0 | 6 votes |
/** * andNot for two negative numbers; the first is longer */ public void testAndNotNegNegFirstLonger() { byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23, 87, -25, -75}; byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23}; int aSign = -1; int bSign = -1; byte rBytes[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 2}; BigInteger aNumber = new BigInteger(aSign, aBytes); BigInteger bNumber = new BigInteger(bSign, bBytes); BigInteger result = aNumber.andNot(bNumber); 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 Project: j2objc File: BigIntegerNotTest.java License: Apache License 2.0 | 6 votes |
/** * andNot for a negative and a positive numbers; the first is longer */ public void testNegPosFirstLonger() { byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23, 87, -25, -75}; byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23}; int aSign = -1; int bSign = 1; byte rBytes[] = {-1, 127, -10, -57, -101, 1, 2, 2, 2, -96, -16, 8, -40, -59, 68, -88, -88, 16, 72}; BigInteger aNumber = new BigInteger(aSign, aBytes); BigInteger bNumber = new BigInteger(bSign, bBytes); BigInteger result = aNumber.andNot(bNumber); 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 5
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 6
Source Project: Walrus File: BinaryFormat.java License: GNU General Public License v3.0 | 5 votes |
protected BigInteger applyAtMyPos(BigInteger target, BigInteger value) { if (length != null) { target = target.andNot(lengthMask().shiftLeft(startPos)); value = value.and(lengthMask()); } return target.or(value.shiftLeft(startPos)); }
Example 7
Source Project: batfish File: Ip6.java License: Apache License 2.0 | 4 votes |
public Ip6 inverted() { BigInteger mask = new BigInteger("+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16); BigInteger invertedBigInteger = mask.andNot(_ip6); return new Ip6(invertedBigInteger); }
Example 8
Source Project: pitest File: BigIntegerMutatorTest.java License: Apache License 2.0 | 4 votes |
@Override BigInteger apply(BigInteger left, BigInteger right) { return left.andNot(right); }