JAVA CODE FOR LEFT SHIFT AND RIGHT SHIFT AND BITWISE OPERATOR

public class Main {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] rk) {
       
        // range of int -2,147,483,648 to 2,147,483,647
        // int is 32bit so below i have taken 32bits
        int a=10; // a= 00000000 00000000 00000000 00001010 = 10 [ten]
        a=a<<2;  // left shift operator
        //now a=00000000 00000000 00000000 00101000 = 40 [fourty]
        System.out.println(“a=”+a);
        // same way right shift operator
       
        int b=2; // ….. 00000010
        int c=2; // ….. 00000010
        int d= c& b; //…00000010      
        System.out.println(“[logican AND] c =”+c);
        d=c|b;
        System.out.println(“[logical OR]  c =”+c);

        // same way change value of b=1 and c=2 then you could uderstand how it works bit by bit.
    }

}

Advertisements

About rajkirpal

i am a software engineer. and i have decent knowledge about java technologies like ANDROID, Servlet, Jsp, Struts, Hibernet, Spring, J2ME, Java Script, Ajax, JQuery, CSS. Further i am Preparing Easy understandable materials/documents upon the same java technologies and developing project in core java , advanced java and j2me , ANDROID as per the requirements Also designing the web sites and logos Thank You.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s