Created
July 25, 2014 04:36
-
-
Save jyhjuzi/ac6f0b44c4db8b804cc5 to your computer and use it in GitHub Desktop.
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
public class Q5_1{ | |
public static void main(String[] args){ | |
int m =0b10011; | |
int n = 0b10000000000; | |
int i = 2; | |
int j = 6; | |
System.out.println(Integer.toBinaryString(insert(m,n,i,j))); | |
} | |
static int insert(int m, int n, int indexI, int indexJ){ | |
// clear the bits between indexI and indexJ | |
int allOne = ~0; | |
int mask = (allOne << (indexJ+1)) | ( 1<<indexJ -1); | |
int newN = n & mask; | |
int newM = m << indexI; | |
return newN | newM; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment