Monday, June 10, 2013

Inverting the Values of given Variable (NOT (~) Operator)

SOURCE CODE

class bitnot { 
        public static void main(String args[]) {      // start of main() method.
                int a = 0, b = 5, c1, c2;     // initializing a & b of type integer.
                c1 = ~a; c2 = ~b;         // inverting a & b using "~" operator and storing in c1 & c2 respectively.
                System.out.println("Inverse : "+c1+ " & " +c2);     // printing result
        }         // ending of main() method.
}      // end of the class.



OUTPUT

Inverse : -1 & -6





NOTE:-
          Not ( ~ ) operator assumes -1 to 0 after inversion.
          Hence whenever we invert any number we get incremented number with negative ( - ) sign.

0 comments:

Post a Comment

    Translate

    Protected by Copyscape