Limited access

Upgrade to access all content for this subject

You are provided with the following Java method, bitMystery, which takes several integers as inputs and produces a result through bit level manipulations.

int bitMystery(int input, int shift, int mask, String maskType) {
    int shifted = (shift > 0 ? input << shift : input >> Math.abs(shift));

    switch(maskType) {
        case "AND":
            return shifted & mask;
        case "OR":
            return shifted | mask;
        case "XOR":
            return shifted ^ mask;
            return shifted;

The bitMystery method makes use of the following operations:

<< - Left shift
>> - Right shift
& - Bitwise and
| - Bitwise or
^ - Bitwise xor

Study the bitMystery method and answer the following questions.

Select an assignment template