BigInteger xor() Method in Java Last Updated : 18 Apr, 2023 Comments Improve Suggest changes Like Article Like Report 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 BigInteger passed as parameter. Syntax: public BigInteger xor(BigInteger val) Parameters: The method accepts one parameter val of BigInteger type and refers to the value to be XOR’ed with this BigInteger. Return Value: The method returns bitwise-XOR of the current BigInteger with the BigInteger val. Examples: Input: value1 = 2300 , value2 = 3400 Output: 1460 Explanation: Binary of 2300 = 100011111100 Binary of 3400 = 110101001000 XOR of 100011111100 and 110101001000 = 10110110100 Decimal of 10110110100 = 1460. Input: value1 = 54298 , value2 = 64257 Output: 12059 Below program illustrate the xor() method of BigInteger Class: Java /* *Program Demonstrate xor() 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 xor() method to find this ^ val BigInteger biggerInteger = biginteger.xor(val); String result = "Result of XOR operation between " + biginteger + " and " + val + " is " + biggerInteger; // Print result System.out.println(result); } } Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#xor(java.math.BigInteger) Comment More infoAdvertise with us Next Article BigInteger xor() 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 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 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 toByteArray() Method in Java The java.math.BigInteger.toByteArray() method returns an array of bytes containing the two's-complement representation of this BigInteger. The most significant byte of the byte array is present in the zeroth element. The returning array from this method contains sign bit and the minimum number of by 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 Bitwise Operators in Java In Java, Operators are special symbols that perform specific operations on one or more than one operands. They build the foundation for any type of calculation or logic in programming.There are so many operators in Java, among all, bitwise operators are used to perform operations at the bit level. T 6 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 ar 3 min read Java BitSet | XOR BitSet is a class defined in the java.util package. It creates an array of bits represented by boolean values. Syntax public void xor(BitSet set); Explanation: The method performs a logical XOR, such that in the BitSet, a bit is set if and only if the bit initially has the value true, and the corres 2 min read Compound Assignment Operators in Java In Java, compound-assignment operators provide a shorter syntax for assigning the result of an arithmetic or bitwise operator. They perform the operation on two operands before assigning the result to the first operand.The following are all possible assignment operators in Java:1. += (compound addit 6 min read StrictMath multiplyExact() Method in Java The multiplyExact(int num1, int num2) is an inbuilt function of StrictMath class in java which is used to get the product of the given arguments. When the result overflows an int i.e. Integer.MAX_VALUE then it throws an exception. Since this function is static so there is no need to create objects. 4 min read Shift Operator in Java Operators in Java are used to performing operations on variables and values. Examples of operators: +, -, *, /, >>, <<. Types of operators: Arithmetic Operator,Shift Operator,Relational Operator,Bitwise Operator,Logical Operator,Ternary Operator andAssignment Operator. In this article, w 4 min read Like