Skip to content

Instantly share code, notes, and snippets.

@chrislukkk
Created July 27, 2014 04:06
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 chrislukkk/61b99ab1015cb05a8cc0 to your computer and use it in GitHub Desktop.
Save chrislukkk/61b99ab1015cb05a8cc0 to your computer and use it in GitHub Desktop.
Career cup 5.6
package Chapter5;
public class SwapBits {
public static int swap(int n) {
int oldEvenBits = 0xAAAAAAAA & n;
int oldOddBits = 0x55555555 & n;
return( (oldOddBits << 1) | (oldEvenBits >> 1) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment