Page 31 - CTS - CSA TP - Volume 2
P. 31
COMPUTER SOFTWARE APPLICATION - CITS
boolean d=false;
System.out.println(~a);//-11 (minus of total positive value which starts from 0)
System.out.println(~b);//9 (positive of total minus, positive starts from 0)
System.out.println(!c);//false (opposite of boolean value)
System.out.println(!d);//true
}}
Explanation:
1 Variable Initialization:
• The program begins by initializing two integer variables a and b with the values 10 and -10, respectively.
• It also initializes two boolean variables c and d with the values true and false, respectively.
2 Bitwise Complement (~):
• System.out.println(~a);
• The bitwise complement (~) operator inverts the bits of the integer a.
• In binary representation, -11 is the two’s complement of 10.
• The output is -11, which is the result of inverting the bits of 10.
• System.out.println(~b);
• The bitwise complement (~) operator inverts the bits of the integer b.
• In binary representation, 9 is the two’s complement of -10.
• The output is 9, which is the result of inverting the bits of -10.
3 Logical NOT (!):
• System.out.println(!c);
• The logical NOT (!) operator negates the boolean value of c.
• The output is false, which is the result of negating the boolean value true.
• System.out.println(!d);
• The logical NOT (!) operator negates the boolean value of d.
• The output is true, which is the result of negating the boolean value false.
Output:
16
CITS : IT & ITES - Computer Software Application - Exercise 82