- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to flip a bit in a BigInteger
To flip a bit in a BigInteger in Java, use the flipBit() method. This method returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped.
Example
import java.math.*; public class Demo { public static void main(String[] args) { BigInteger one, two; one = new BigInteger("7"); one = one.flipBit(3); System.out.println("Result: " +one); } }
Output
Result: 15
Let us see another example.
Example
import java.math.*; public class Demo { public static void main(String[] args) { BigInteger bi1, bi2; bi1 = new BigInteger("8"); bi2 = bi1.flipBit(1); String str = "Flipbit operation on " +bi1+ " at index 1 gives " +bi2; System.out.println( str ); } }
Output
Flipbit operation on 8 at index 1 gives 10
- Related Articles
- Clear a bit in a BigInteger in Java
- Set a bit for BigInteger in Java
- Java Program to shift bits in a BigInteger
- Java Program to create random BigInteger within a given range
- Negate a BigInteger in Java
- Multiply one BigInteger to another BigInteger in Java
- Shift right in a BigInteger in Java
- Shift left in a BigInteger in Java
- Java Program to perform XOR operation on BigInteger
- Java Program to perform AND operation on BigInteger
- Java Program to implement NOT operation on BigInteger
- Java Program to implement OR operation on BigInteger
- Java Program to implement andNot operation on BigInteger
- How to generate a random BigInteger value in Java?
- Subtract one BigInteger from another BigInteger in Java

Advertisements