Home Java Master-java Java Left Shift "<<" Operator
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java Left Shift "<<" Operator

Advertisement
In this section, you will learn how to use Left Shift "<<" operator in Java. The Java programming language has operators that perform bitwise operations.

Java Left Shift "<<" Operator

     

In this section, you will learn how to use Left Shift "<<" operator in Java. The Java programming language has operators that perform bitwise operations. In the example below we have shown the usage of  Left Shift "<<" operator.

Description of code:

The
Left Shift "<<" operator shifts the left operand to the left side by the number of bits specified by its right operand. This operator never throws an exception. Each operand of the left shift operator must be an integer data type otherwise a compile-time error will occur. The following example shows displays the code of left shift operator. 

Here is the code of program: 

public class leftshift
 public static void main(String args[]){
 System.out.println(" << opeartor");
 System.out.println(" -9 << 3 = " +-<< 3));
 System.out.println("  9 << 3 = " +(  << 3));
  }
}

Output of the program:

C:\unique>javac leftshift.java

C:\unique>java leftshift
<< opeartor
-9 << 3 = -72
9 << 3 = 72

C:\unique>

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 3, 2008

Ask Questions?    Discuss: Java Left Shift "<<" Operator   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com