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 singned bit of BigInteger.
public BigInteger negate()
Parameters: The method does not accept any parameter.
Return Value: The method returns the operation of (- this).
Input: value = 2300 Output: -2300 Explanation: Binary signed 2's complement of 2300 = 0000100011111100 Singed bit are 0000 change sing bit to 1111 so negate of 0000100011111100 in signed 2's complement is 1111011100000100 Decimal value = -2300. Input: value = 567689 Output: -567689
Below program illustrates negate() method of BigInteger.
Result of negate operation on 2300 is -2300
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.