
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implement AND-NOT Operation on BigInteger in Java
TheBigInteger.andNot(BigInteger val) returns a BigInteger whose value is (this & ~val). 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. Here, “val” is the value to be complemented and AND'ed with this BigInteger.
The following is an example −
Example
import java.math.*; public class Demo { public static void main(String[] args) { BigInteger one, two, three; one = new BigInteger("12"); two = new BigInteger("6"); three = one.andNot(two); System.out.println("Result (andNot operation): " +three); } }
Output
Result (andNot operation): 8
Let us see another example −
Example
import java.math.*; public class Demo { public static void main(String[] args) { BigInteger bi1, bi2, bi3; bi1 = new BigInteger("9"); bi2 = new BigInteger("2"); bi3 = bi1.andNot(bi2); String str = "Result of andNot operation is " +bi3;; System.out.println( str ); } }
Output
Result of andNot operation is 9
Advertisements