# Java MCQ Questions and Answers on Bitwise Operators 1 | Java MCQ Questions and Answers on Bitwise Operators

Study and learn Java MCQ Questions and Answers on Bitwise Operators and their priorities. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save As PDF option next using a Google Chrome browser or any other browser.

Go through Java Theory Notes on Bitwise Operators before reading the questions.

1) Identify the Bitwise NOT operator in Java below.

A)

!

B)

&

C)

~

D) None of the above

C

Explanation:

It negates the bit 1 to 0 and bit 0 to 1.

2) Bitwise operators in Java work with?

A) boolean data like true or false

B) Real numbers like float or double

C) Individual bits of integers like byte, short, int, long and char

D) All the above

C

3) Find operators that work as both Logical operators and Bitwise operators in Java?

A)

&, &=

B)

|, |=

C)

^, ^=

D) All the above

D

4) If relational operators are present in an expression, what type of other operators may be used?

A) Logical operators

B) Bitwise operators

C) A and B

D) None of the above

A

Explanation:

Logical & is used here.

(a>5) & (b<10)

5) What is the name of << bitwise operator in Java?

A) Right Shift Operator

B) Left Shift Operator

C) Left Shift Fill Zero operator

D) Right Shift Fill Zero operator

B

Explanation:

Left shift operator shifts individual bits from right side to the left side.

6) What is this >> bitwise operator in Java?

A) Left shift operator

B) Right shift operator

C) Left Shift Fill Zero operator

D) Right Shift Fill Zero operator

B

Explanation:

Right Shift operator shifts individual bits of a number from left side to the right side maintaining the sign of the number. So, a negative number is still a negative number after the right shift operation.

7) What is this >>> bitwise operator in Java?

A) Left Shift operator

B) Left Shift Fill Zero operator

C) Right Shift Operator

D) Right Shift Fill Zero operator

D

Explanation:

>>> (Right Shift Fill Zero) operator fills the left side gaps created by shifting with Zeros thus losing the sign of the number.

8) Left Shift (<<) in Java is equivalent to?

A) Subtracting the number by 2

B) Dividing the number by 2

C) Multiplying the number by 2

D) Adding the number by 2

C

Explanation:

byte a = 0b0000_0001; //1

a = a << 1;

//a now holds 0000_0010 //2

9) Right Shift >> in Java is equivalent to?

A) Multiplying the number by 2

B) Dividing the number by 2`

C) Subtracting the number by 2

D) Adding the number by 2

B

Explanation:

byte a = 0b0000_0100; //4

a = a >> 1;

//a now holds 0000_0010 i.e 2

10) What is the output of the Java code snippet?

byte a = 0b0000_0001;

System.out.println(~a);

A) -1

B) -2

C) 254

D) +127

B

Explanation:

a = 0b0000_0001; //1

~a = 1111_1110; //254

Byte rannge is -128 to +127.

So, overflown 255 goes

to the negative side

11) What does this Java code snippet prints?

int b=45;

String str=””;

while(b > 0)

{

str = str + b%2;

b = b/2;

}

StringBuilder sb = new StringBuilder(str);

sb.reverse();

System.out.println(sb.toString());

A) Prints the remainder of a number

B) Prints Binary representation of a number

C) Prints Octal representation of a number

D) Prints Hexadecimal representation of a number

B

Explanation:

The output is 101101 (45).

12) What is the output of the Java code snippet?

System.out.println(0b0000_1000);

A) 0b0000_1000

B) 1000

C) 8

D) 9

C

Explanation:

Binary literals start with 0b. Above number is 8 in decimal notation.

13) What is the output of a Bitwise AND (&) operation if both the inputs/operands are 1s?

A) 0

B) 1

C) 0 or 1

D) None of the above

B

Explanation:

1 & 1 = 1

14) What is the output of a Bitwise OR (|) operation if both the inputs are 1s?

A) 0

B) 1

C) 0 or 1

D) None of the above

B

Explanation:

1 | 1 = 1

15) What is the output of a Bitwise AND (&) operation if one of the inputs/operands is 0?

A) 0

B) 1

C) 0 or 1

D) None of the above

A

Explanation:

0 & (anything) = 0

16) What is the output of a Bitwise OR (|) operation if one of the inputs/operands is 1?

A) 0

B) 1

C) 0 or 1

D) None of the above

B

Explanation:

1 | (anything) = 1

17) What is the output of a Bitwise AND (&) operation if one of the inputs/operands is 1?

A) 0

B) 1

C) 0 or 1

D) None of the above

C

Explanation:

1 & (P) = 1 if P=1

1 & (P) = 0 if P=0

18) What is the output of a Bitwise OR (|) operation if one of the inputs/operands is 0?

A) 0

B) 1

C) 0 or 1

D) None of the above

C

Explanation:

0 | P = 1 if P==1

0 | P = 0 if P==0

19) What is the output of a Bitwise Exclusive OR (^) operation if both of the inputs/operands are 0s or 1s?

A) 0

B) 1

C) 0 or 1

D) None of the above

A

Explanation:

0 ^ 0 = 0;

1 ^ 1 = 1;

20) What is the output of a Bitwise Exclusive OR (^) operation if both the inputs/operands are different?

A) 0

B) 1

C) 0 or 1

D) None of the above