Return to Snippet

Revision: 70530
at March 30, 2016 01:54 by m3hdiii


Initial Code
import java.math.BigInteger;

/**
 * @author Mehdi
 */
public class Launcher {
    public static void main(String[] args) {
        System.out.println(BitwiseUtils.doBitwise("00101010", "00001111", 2, BitwiseUtils.BitwiseOperator.XOR));
    }
}


class BitwiseUtils {
    public enum BitwiseOperator {
        AND, OR, XOR
    }

    public static String doBitwise(String number1, String number2, int radix, BitwiseOperator bitwiseOperator) {
        BigInteger bn1 = new BigInteger(number1, radix);
        BigInteger bn2 = new BigInteger(number2, radix);
        switch (bitwiseOperator) {
            case AND:
                return bn1.and(bn2).toString(radix);
            case OR:
                return bn1.or(bn2).toString(radix);
            case XOR:
                return bn1.xor(bn2).toString(radix);

        }

        return null;
    }
}

Initial URL

                                

Initial Description
This Utility Class will receive two big number and do the Bitwise Operation on them using specific radix.

Initial Title
Big Number Bitwise Operator

Initial Tags
java

Initial Language
Java