1) Identify the Bitwise NOT operator in Java below.
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
3) Find operators that work as both Logical operators and Bitwise operators in Java?
4) If relational operators are present in an expression, what type of other operators may be used?
A) Logical operators
Explanation:
Logical & is used here.
(a>5) & (b<10)
5) What is the name of << bitwise operator in Java?
A) Right Shift Operator
C) Left Shift Fill Zero operator
D) Right Shift Fill Zero operator
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
C) Left Shift Fill Zero operator
D) Right Shift Fill Zero operator
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
D) Right Shift Fill Zero operator
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
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
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
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
Explanation:
The output is 101101 (45).
12) What is the output of the Java code snippet?
System.out.println(0b0000_1000);
A) 0b0000_1000
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
14) What is the output of a Bitwise OR (|) operation if both the inputs are 1s?
A) 0
15) What is the output of a Bitwise AND (&) operation if one of the inputs/operands is 0?
A) 0
Explanation:
0 & (anything) = 0
16) What is the output of a Bitwise OR (|) operation if one of the inputs/operands is 1?
A) 0
Explanation:
1 | (anything) = 1
17) What is the output of a Bitwise AND (&) operation if one of the inputs/operands is 1?
A) 0
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
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
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
Explanation:
0 ^ 1 = 1;
1 ^ 0 = 1;