Open In App

BigInteger not() Method in Java

Last Updated : 04 Dec, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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: The method does not take any parameters.

Return Value: The method returns the bitwise-NOT value of a BigInteger with which it is used.

Examples:

Input: value = 2300
Output: -2301
Explanation:
Binary of 2300 = 100011111100
NOT of 100011111100 in signed 2's complement is 1111011100000011
Decimal value = -2301.

Input: value = 567689 
Output: -567690

Below program illustrate the not() method of BigInteger():




/*
*Program Demonstrate not() method of BigInteger 
*/
import java.math.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Creates  BigInteger object
        BigInteger biginteger = new BigInteger("2300");
  
        // Call not() method to find ~this
        BigInteger finalvalue = biginteger.not();
        String result = "Result of NOT operation on "
        biginteger + " is " + finalvalue;
  
        // Print result
        System.out.println(result);
    }
}


Output:

Result of NOT operation on 2300 is -2301

Reference:https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#and(java.math.BigInteger)


Similar Reads

Java.math.BigInteger.modInverse() method in Java
Prerequisite : BigInteger Basics The modInverse() method returns modular multiplicative inverse of this, mod m. This method throws an ArithmeticException if m <= 0 or this has no multiplicative inverse mod m (i.e., gcd(this, m) != 1). Syntax: public BigInteger modInverse(BigInteger m) Parameters: m - the modulus. Return Value: This method return
2 min read
Java.math.BigInteger.probablePrime() method in Java
Prerequisite : BigInteger Basics The probablePrime() method will return a Biginteger of bitLength bits which is prime. bitLength is provided as parameter to method probablePrime() and method will return a prime BigInteger of bitLength bits. The probability that a BigInteger returned by this method is composite and does not exceed 2^-100. Syntax: pu
2 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 when number is positive Syntax: public int signum
2 min read
BigInteger shiftRight() Method in Java
prerequisite : BigInteger Basics The java.math.BigInteger.shiftRight(int n) method returns a BigInteger whose value is (this >> n). The shift distance, n, may be negative, in which case this method performs a left shift. The shiftRight() method will move each digit in a number's binary representation right by n times and the last bit in the d
2 min read
Java 8 | BigInteger divideAndRemainder() method with Examples
java.math.BigInteger.divideAndRemainder(BigInteger val) was introduced in Java 8. This method returns an array of two BigInteger after applying division operation between the BigInteger calling this method and the BigInteger passed as a parameter to the other method. Here, First BigInteger of the array represents a result of the division (this / va
3 min read
BigInteger abs() Method in Java
prerequisite : BigInteger Basics The java.math.BigInteger.abs() method returns absolute value of a BigInteger. By using this method one can find absolute value of any large size of numerical data stored as BigInteger. Syntax: public BigInteger abs() Parameters: The method does not take any parameters. Return Value: The method returns the absolute v
1 min read
BigInteger modPow() Method in Java
Prerequisite: BigInteger BasicsThe Java.math.BigInteger.modPow() method returns a BigInteger whose value is (thisexponent mod m ). If exponent == 1, the returned value is (this mod m) and if exponent < 0, the returned value is the modular multiplicative inverse of (this-exponent). The method throws an ArithmeticException if m <= 0. Syntax: pu
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 with the function is negative. OR() method of BigInte
2 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-XOR operation upon the current BigInteger and Big
2 min read
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 parameter.Syntax: public BigInteger and(BigInteger
2 min read