92). Which of these is not a bitwise operator?
Show Answer
Correct Answer: <=
Notes:
Answer: d
Explanation: <= is a relational operator.
93). Which operator is used to invert all the digits in a binary representation of a number?
Show Answer
Correct Answer: ~
Notes:
Answer: a
Explanation: Unary not operator, ~, inverts all of the bits of its operand in binary representation.
94). On applying Left shift operator, <<, on integer bits are lost one they are shifted past which position bit?
Show Answer
Correct Answer: 31
Notes:
Answer: d
Explanation: The left shift operator shifts all of the bits in a value to the left specified number of times. For each shift left, the high order bit is shifted out and lost, zero is brought in from the right. When a left shift is applied to an integer operand, bits are lost once they are shifted past the bit position 31.
95). Which right shift operator preserves the sign of the value?
[A]<<
[B]>>
[C]<<=
[D]>>=
Show Answer
Correct Answer: >>
Notes:
Answer: b
Explanation: None.
96). Which of these statements are incorrect?
[A]The left shift operator, <<, shifts all of the bits in a value to the left specified number of times
[B]The right shift operator, >>, shifts all of the bits in a value to the right specified number of times
[C]The left shift operator can be used as an alternative to multiplying by 2
[D]The right shift operator automatically fills the higher order bits with 0
Show Answer
Correct Answer: The right shift operator automatically fills the higher order bits with 0
Notes:
Answer: d
Explanation: The right shift operator automatically fills the higher order bit with its previous contents each time a shift occurs. This also preserves the sign of the value.
97). What will be the output of the following Java program?
class bitwise_operator
{
public static void main(String args[])
{
int var1 = 42;
int var2 = ~var1;
System.out.print(var1 + " " + var2);
}
}
[A]42 42
[B]43 43
[C]42 -43
[D]42 43
Show Answer
Correct Answer: 42 -43
Notes:
Answer: c
Explanation: Unary not operator, ~, inverts all of the bits of its operand. 42 in binary is 00101010 in using ~ operator on var1 and assigning it to var2 we get inverted value of 42 i:e 11010101 which is -43 in decimal.
output:$ javac bitwise_operator.java
$ java bitwise_operator
42 -43
98). What will be the output of the following Java program?
class bitwise_operator
{
public static void main(String args[])
{
int a = 3;
int b = 6;
int c = a | b;
int d = a & b;
System.out.println(c + " " + d);
}
}
[A]7 2
[B]7 7
[C]7 5
[D]5 2
Show Answer
Correct Answer: 7 2
Notes:
Answer: a
Explanation: And operator produces 1 bit if both operand are 1. Or operator produces 1 bit if any bit of the two operands in 1.
output:
$ javac bitwise_operator.java
$ java bitwise_operator
7 2
99). What will be the output of the following Java program?
class leftshift_operator
{
public static void main(String args[])
{
byte x = 64;
int i;
byte y;
i = x << 2;
y = (byte) (x << 2)
System.out.print(i + " " + y);
}
}
[A] 0 64
[B]64 0
[C]0 256
[D]256 0
Show Answer
Correct Answer: 256 0
Notes:
Answer: d
Explanation: None.
output:
$ javac leftshift_operator.java
$ java leftshift_operator
256 0
100). What will be the output of the following Java program?
class rightshift_operator
{
public static void main(String args[])
{
int x;
x = 10;
x = x >> 1;
System.out.println(x);
}
}
Show Answer
Correct Answer: 5
Notes:
Answer: b
Explanation: Right shift operator, >>, devides the value by 2.
output:
$ javac rightshift_operator.java
$ java rightshift_operator
5
101). What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
int a = 1;
int b = 2;
int c = 3;
a |= 4;
b >>= 1;
c <<= 1;
a ^= c;
System.out.println(a + " " + b + " " + c);
}
}
[A] 3 1 6
[B]2 2 3
[C] 2 3 4
[D] 3 3 6
Show Answer
Correct Answer: 3 1 6
Notes:
Answer: a
Explanation: None.
output:
$ javac Output.java
$ java Output
3 1 6