Question
class bitwise_operator {
public static void main(String args[])
{
int var1 = 42;
int var2 = ~var1;
System.out.print(var1 + " " + var2);
}
}
What is the output of this program?
class bitwise_operator {
public static void main(String args[])
{
int var1 = 42;
int var2 = ~var1;
System.out.print(var1 + " " + var2);
}
}
Answer: Option C
Was this answer helpful ?
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
Was this answer helpful ?
More Questions on This Topic :
Question 3.
Which of these statements are incorrect?
....
Question 4.
Which of these statements are incorrect?
....
Question 7.
Which of these statements are incorrect?
....
Submit Solution