Skip to content

Instantly share code, notes, and snippets.

@astkaasa
Created April 16, 2013 02:00
Show Gist options
  • Save astkaasa/5392778 to your computer and use it in GitHub Desktop.
Save astkaasa/5392778 to your computer and use it in GitHub Desktop.
problem 5.6
public class BitSwap {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a = 0b10001111;
int b = a >> 1;
int c = 0;
int i = 0;
int mask = ~ ( ( ~ 0 ) << 2 );
while ( a != 0 ) {
c = c | ( a << 1 & mask | b ) << i;
i += 2;
a = a >> 2;
b = b >> 2;
}
System.out.println( Integer.toBinaryString( c ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment