How To Implement Shift Operators In Java
Rate this article
0 out of 5
In this tutorial we will show you how to implement shift operators in java. After viewing the video tutorial, download the source code and try to modify the code so as to get a feel of what is learned in this video tutorial.

 
Source Code
shiftoperation.java

//program to demonstrate shift operations

public class shiftoperation
{
public static void main(String args[])
{
int a=-67890346;
int o1=a<<3; // left shift
int o2=a>>3;  // right shift
int o3=a>>>3; //unsigned right shift
System.out.println("The original value is"+ShiftBit(a));
System.out.println("the left shift value is"+ShiftBit(o1));
System.out.println("The right shift value is"+ShiftBit(o2));
System.out.println("The unsigned shift value is"+ShiftBit(o3));
}
 private static String ShiftBit(int x)
 {
      StringBuffer buf = new StringBuffer();

      for (int i=1; i<=32; i++) 

      buf.append(x>>>(32-i) & 0x00000001);
      return buf.toString();
   }
}


Source Code

Joined Date : 04/02/2013
Articles
Posted
27
Messages
Posted
0


Click Here to See Full Profile
   
Author
Messages
Posted:
Post Your Comments
Name (Max 50 Chars)
Comments

 
TekTipsDownload
GateExam
Academic Projects
TekTipsExperts
Android