Wednesday, 4 November 2015

Java Tutorial : Java bitwise Left Right and Shift Operators


Click here to watch in Youtube :
https://www.youtube.com/watch?v=SW8dzYAtdwk&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java bitwise Left Right and Shift Operators
Java Tutorial : Java bitwise Left Right and Shift Operators
Java Tutorial : Java bitwise Left Right and Shift Operators
BitwiseLeftShiftOperatorDemo.java
class BitwiseLeftShiftOperatorDemo
{
    public static void main(String[] args)
    {

        int a = 52; // 00110100

        System.out.println("binary of 'a'                       :   "
                + Integer.toBinaryString(a) + "\n");

        /*
         * Number of bits needs to be moved to left.
         */
        int b = 2;

        /*
         * The left operands value is moved left by the number of bits specified
         * by the right operand.
         */
        int value = a << b; // 11010000

        System.out.println("binary of 'value' after Left shift  : "
                + Integer.toBinaryString(value));
        System.out.println("value : " + value);

    }
}
Output
binary of 'a'                       :   110100

binary of 'value' after Left shift  : 11010000
value : 208
BitwiseRightShiftOperatorDemo.java
public class BitwiseRightShiftOperatorDemo
{
    public static void main(String[] args)
    {

        int a = 172; // 10101100
        
        System.out.println("binary of 'a'                        : "
                + Integer.toBinaryString(a) + "\n");

        /*
         * Number of bits needs to be moved to right.
         */
        int b = 1;

        /*
         * The left operand value is moved right by the number of bits
         * specified by the right operand.
         */
        int value = a >> b; // 01010110

        System.out.println("binary of 'value' after Right shift  :  "
                + Integer.toBinaryString(value));
        System.out.println("value: " + value);

    }
}
Output
binary of 'a'                        : 10101100

binary of 'value' after Right shift  :  1010110
value: 86
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/OperatorsDemoRightLeftShiftOperatorApp.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/OperatorsDemoRightLeftShiftOperatorApp

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/9c29c9c8cf10305cf0952ccfd17cdec26383c2e4/BasicJava/OperatorsDemoRightLeftShiftOperatorApp/?at=master

Refer:
http://www.binaryhexconverter.com/binary-to-decimal-converter

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment