BigInteger andNot() Method in Java Last Updated : 24 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The java.math.BigInteger.andNot(BigInteger val) method returns a BigInteger whose value is (this & ~val) where this to the current BigInteger with which the function is being used and val is the bigInteger passed to the function as a parameter. This method, which is equivalent to and(val.not()), is provided as a convenience for masking operations. This method returns a negative BigInteger if and only if this is negative and val is positive. The andNOT() method apply bitwise AND operation upon the current bigInteger and NOT value of bigInteger passed as parameter. Syntax: public BigInteger andNot(BigInteger val) Parameters: The method accepts one parameter val BigInteger type and refers to the value that needs to be complemented and AND'ed with the current BigInteger. Return Value: The method is used to return (this & ~val) where this to the current BigInteger with which the function is being used and val is the bigInteger passed to the function as a parameter. Examples: Input: value1 = 2300, value2 = 3400 Output: 180 Explanation: Binary of 2300 = 100011111100 Not of 3400 in binary signed 2's complement is 1111001010110111 AND of 100011111100 and 1111001010110111= 10110100 Decimal of 10110100 = 180. Input: value1 = 432045, value2 = 321076 Output: 135561 Below programs illustrate the andNot() method of BigInteger. Example 1 Java // Program Demonstrate andNot() method of BigInteger import java.math.*; public class GFG { public static void main(String[] args) { // Create 2 BigInteger objects BigInteger biginteger = new BigInteger("2300"); BigInteger val = new BigInteger("3400"); // Call andNot() method to find this & ~val BigInteger finalvalue = biginteger.andNot(val); String result = "Result of andNot operation between " + biginteger + " and " + val + " is " + finalvalue; // Print the result System.out.println(result); } } Output:Result of andNot operation between 2300 and 3400 is 180 Example 2: Java import java.io.*; import java.math.BigInteger; public class GFG { public static void main(String[] args) { BigInteger bi1 = new BigInteger("101010", 3); BigInteger bi2 = new BigInteger("111100", 3); BigInteger result = bi1.andNot(bi2); System.out.println("b1 = " + bi1.toString(2)); System.out.println("b2 = " + bi2.toString(2)); System.out.println("result = " + result.toString(2)); } } Outputb1 = 100010001 b2 = 101101000 result = 10001 Comment More infoAdvertise with us Next Article BigInteger andNot() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-lang package Java-Functions java-math Java-BigInteger Java-math-package +2 More Practice Tags : JavaJava-BigInteger Similar Reads BigInteger and() Method in Java The java.math.BigInteger.and(BigInteger val) method returns a BigInteger whose value is bitwise-AND of two BigIntegers. This method returns a negative number if both of the BigIntegers are negative. The and() method applies bitwise-AND operation upon the current bigInteger and bigInteger passed as p 2 min read BigInteger or() method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.or(BigInteger val) method is used to perform bitwise OR of two BigIntegers. One of the BigInteger is passed in parameter and the other on which the function is called. This method returns a negative number if either of the BigIntegers used wit 2 min read BigInteger max() and min() Methods in Java Prerequisite: BigInteger Basics BigInteger max() method: The max() method of the BigInteger returns the BigInteger whose value is the greater between current BigInteger and BigInteger passed as a parameter to the method. If both the values are equal, either may be returned. There is a similar method 3 min read BigInteger not() Method in Java The java.math.BigInteger.not() method is used to find the bitwise-NOT of a BigInteger. This method returns a negative value if and only if this BigInteger is non-negative. The BigInteger.not() method apply bitwise Not operation upon the current bigInteger. Syntax: public BigInteger not() Parameters: 1 min read BigInteger xor() Method in Java Prerequisite: BigInteger Basics The xor(BigInteger val) method returns bitwise-XOR of two bigIntegers. This method returns a negative BigInteger if and only if exactly one of the current bigInteger and the bigInteger passed in parameter id negative. The xor() method of BigInteger class apply bitwise 2 min read BigInteger equals() Method in Java The java.math.BigInteger.equals(Object x) method compares this BigInteger with the object passed as the parameter and returns true in both are equal in value else it returns false. Syntax: public boolean equals(Object x) Parameter: This method accepts a single mandatory parameter x which is the Obje 3 min read BigInteger negate() Method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.negate() method returns a BigInteger whose value is (- this). negate() method will change the signed bit of BigInteger. Syntax: public BigInteger negate() Parameters: The method does not accept any parameter. Return Value: The method returns t 1 min read BigInteger signum() Method in Java prerequisite : BigInteger Basics The java.math.BigInteger.signum() method helps us to identify whether a BigInteger is positive or zero or negative. It returns one of the following values depending on the following conditions: returns -1 when number is negativereturns 0 when number is zeroreturns +1 2 min read BigInteger testBit() Method in Java prerequisite : BigInteger Basics The java.math.BigInteger.testBit(index) method returns true if and only if the designated bit is set. This method Computes (this & (1<<n)) != 0). Syntax: public boolean testBit(int n) Parameter: The method takes one parameter n of integer type which refers 2 min read BigInteger bitCount() Method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.bitCount() method returns number of bits in the two's complement representation of this BigInteger that differ from its sign bit. This method is useful when implementing bit-vector style sets atop BigIntegers.Syntax: public int bitCount() Para 1 min read Like