Created
October 9, 2016 15:20
-
-
Save Jessica121/1d0a52e92b5fae1b040de9b7654da506 to your computer and use it in GitHub Desktop.
A 64-bit integer can be viewed as an array of 64 bits, with the bit at index 0 corresponding to the least significant bi.t,and the bit at index 63corresponding to the most significant bit. Implement code that tnJces as input a 64-bit integer x and swaps t
This file contains hidden or 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
import java.util.Scanner; | |
import java.lang.Math; | |
public class swapBits { | |
public static long bitswap(long x,int i, int j) | |
{ | |
long y=((x>>i)^(x>>j))&1; | |
return x^((y<<i)|(y<<j)); | |
} | |
public static void main(String[] args) | |
{ | |
long input; | |
Scanner in= new Scanner(System.in); | |
System.out.println("input number,i and j"); | |
input=in.nextLong(); | |
int i=in.nextInt(); | |
int j=in.nextInt(); | |
System.out.println(bitswap(input,i,j)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment