Created
July 27, 2014 04:06
-
-
Save chrislukkk/61b99ab1015cb05a8cc0 to your computer and use it in GitHub Desktop.
Career cup 5.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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