Test Series - java

Test Number 23/64

Q: Identify the Bitwise NOT operator in Java below.
A. !
B. &
C. ~
D. None of the above
Solution: It negates the bit 1 to 0 and bit 0 to 1.
Q: 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
Solution: no solution
Q: Find operators that work as both Logical operators and Bitwise operators in Java?
A. &, &=
B. |, |=
C. ^, ^=
D. All the above
Solution: no solution
Q: 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
Solution: Logical & is used here.
(a>5) & (b<10)
Q: 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
Solution: Left shift operator shifts individual bits from right side to the left side.
Q: 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
Solution: 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.
Q: 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
Solution: >>> (Right Shift Fill Zero) operator fills the left side gaps created by shifting with Zeros thus losing the sign of the number.
Q: 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
Solution: byte a = 0b0000_0001; //1
a = a << 1;
//a now holds 0000_0010 //2
Q: 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
Solution: byte a = 0b0000_0100; //4
a = a >> 1;
//a now holds 0000_0010 i.e 2
Q: 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
Solution: a = 0b0000_0001; //1
~a = 1111_1110; //254
Byte rannge is -128 to +127.
So, overflown 255 goes
to the negative side

You Have Score    /10