Q. What is the output of this program?

Code:
public class Bitwise_Operator 
    {
        public static void main(String args[])
        {
            int num1 = 30;
            int num2 = ~num1;
            System.out.print(num1 + " " + num2);     	
        } 
    }
  • (A) 30 -31
  • (B) 40 -40
  • (C) 30 -30
  • (D) 31 -30
πŸ’¬ Discuss
βœ… Correct Answer: (A) 30 -31
Explanation: Unary not operator, ~, inverts all of the bits of its operand. 30 in binary is 00011110 in using ~ operator on num1 and assigning it to num2 we get inverted value of 30 i:e 11100001 which is -31 in decimal.
output: 30 -31
Explanation by: Rajeev Malhotra
Unary not operator, ~, inverts all of the bits of its operand. 30 in binary is 00011110 in using ~ operator on num1 and assigning it to num2 we get inverted value of 30 i:e 11100001 which is -31 in decimal.
output: 30 -31

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
386
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Rajeev Malhotra
Publisher
πŸ“ˆ
85%
Success Rate