Skip to content

Instantly share code, notes, and snippets.

@bitcpf
Created August 5, 2014 00:42
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 bitcpf/8d741b6cad060a205559 to your computer and use it in GitHub Desktop.
Save bitcpf/8d741b6cad060a205559 to your computer and use it in GitHub Desktop.
public class Q5_6 {
public static void main(String[] args){
int test = 73;
System.out.println(Integer.toBinaryString(test));
System.out.println(Integer.toBinaryString(SwapEvenOdd(test)));
}
public static int SwapEvenOdd(int n){
int tempOdd = (n & 0x55555555) << 1;
int tempEven = (n & 0xaaaaaaaa) >> 1;
return tempOdd | tempEven;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment