Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active February 22, 2016 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/500e09876f48ae22c1a7 to your computer and use it in GitHub Desktop.
Save thmain/500e09876f48ae22c1a7 to your computer and use it in GitHub Desktop.
public class BinaryRotate {
public int rotateBinary(int number){
int res = 0;
while(number>0){
res=res<<1;
res = res|(number & 1);
number=number>>1;
}
return res;
}
public static void main(String args[]){
int x =30;
BinaryRotate b = new BinaryRotate();
System.out.println("Binary rotation of "+ x + " is : " + b.rotateBinary(x));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment