Skip to content

Instantly share code, notes, and snippets.

@bitcpf
Created August 4, 2014 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bitcpf/4557650885e95e0e41cb to your computer and use it in GitHub Desktop.
Save bitcpf/4557650885e95e0e41cb to your computer and use it in GitHub Desktop.
public class Q5_1 {
public static void main(String[] args){
int m =0b10011;
int n = 0b10000000001;
int i = 2;
int j = 6;
System.out.println(Integer.toBinaryString(InsertMN(m,n,i,j)));
}
public static int InsertMN(int m, int n, int i,int j){
int allone = ~0;
// System.out.println(Integer.toBinaryString(~(allone << i)));
int mask = (allone << (j+1))|~(allone << i);
// System.out.println(Integer.toBinaryString(mask));
int tempN = n & mask;
int tempM = m << i;
return tempN|tempM;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment