Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Scanner;
- public class _5_BitFlipper {
- private static final BigInteger SEVEN = new BigInteger("7");
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- BigInteger number = scan.nextBigInteger();
- BigInteger bitMask;
- BigInteger bitValue;
- for (int position = 63; position >= 2; position--) {
- bitMask = SEVEN.shiftLeft(position - 2);
- bitValue = number.and(bitMask);
- bitValue = bitValue.shiftRight(position - 2);
- if (bitValue.equals(BigInteger.ZERO)) {
- number = number.or(bitMask);
- position -= 2;
- } else if (bitValue.equals(SEVEN)) {
- number = number.andNot(bitMask);
- position -= 2;
- }
- }
- System.out.println(number);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement