# BigInteger andNot() Method in Java

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 program illustrate the andNot() method of BigInteger.

 `/* ` `*Program Demonstrate notNot() 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
```

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : 29AjayKumar

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.