@Test public void testInsertMIntoN() { Assert.assertEquals(2124, PracticeQuestionsCh5.insertMIntoN(2048, 19, 2, 6)); }
public static int insertMIntoN(int N, int M, int i, int j) { LOGGER.debug("N = {}, M = {}, i = {}, j = {}.", N, M, i, j); final int mask1 = ~0 << (j + 1); final int mask2 = (1 << i) - 1; final int mask = mask1 | mask2; final int maskAndN = mask & N; final int leftShiftedM = M << i; LOGGER.debug("mask 1 = {}, mask 2 = {}.", mask1, mask2); LOGGER.debug("mask = {}.", mask); LOGGER.debug("maskAndN = {}.", maskAndN); LOGGER.debug("leftShiftedM = {}.", leftShiftedM); return maskAndN | leftShiftedM; }
PracticeQuestionsCh5 { public static int insertMIntoN(int N, int M, int i, int j) { LOGGER.debug("N = {}, M = {}, i = {}, j = {}.", N, M, i, j); final int mask1 = ~0 << (j + 1); final int mask2 = (1 << i) - 1; final int mask = mask1 | mask2; final int maskAndN = mask & N; final int leftShiftedM = M << i; LOGGER.debug("mask 1 = {}, mask 2 = {}.", mask1, mask2); LOGGER.debug("mask = {}.", mask); LOGGER.debug("maskAndN = {}.", maskAndN); LOGGER.debug("leftShiftedM = {}.", leftShiftedM); return maskAndN | leftShiftedM; } }
PracticeQuestionsCh5 { public static int insertMIntoN(int N, int M, int i, int j) { LOGGER.debug("N = {}, M = {}, i = {}, j = {}.", N, M, i, j); final int mask1 = ~0 << (j + 1); final int mask2 = (1 << i) - 1; final int mask = mask1 | mask2; final int maskAndN = mask & N; final int leftShiftedM = M << i; LOGGER.debug("mask 1 = {}, mask 2 = {}.", mask1, mask2); LOGGER.debug("mask = {}.", mask); LOGGER.debug("maskAndN = {}.", maskAndN); LOGGER.debug("leftShiftedM = {}.", leftShiftedM); return maskAndN | leftShiftedM; }  }
PracticeQuestionsCh5 { public static int insertMIntoN(int N, int M, int i, int j) { LOGGER.debug("N = {}, M = {}, i = {}, j = {}.", N, M, i, j); final int mask1 = ~0 << (j + 1); final int mask2 = (1 << i) - 1; final int mask = mask1 | mask2; final int maskAndN = mask & N; final int leftShiftedM = M << i; LOGGER.debug("mask 1 = {}, mask 2 = {}.", mask1, mask2); LOGGER.debug("mask = {}.", mask); LOGGER.debug("maskAndN = {}.", maskAndN); LOGGER.debug("leftShiftedM = {}.", leftShiftedM); return maskAndN | leftShiftedM; }  static int insertMIntoN(int N, int M, int i, int j); }
PracticeQuestionsCh5 { public static int insertMIntoN(int N, int M, int i, int j) { LOGGER.debug("N = {}, M = {}, i = {}, j = {}.", N, M, i, j); final int mask1 = ~0 << (j + 1); final int mask2 = (1 << i) - 1; final int mask = mask1 | mask2; final int maskAndN = mask & N; final int leftShiftedM = M << i; LOGGER.debug("mask 1 = {}, mask 2 = {}.", mask1, mask2); LOGGER.debug("mask = {}.", mask); LOGGER.debug("maskAndN = {}.", maskAndN); LOGGER.debug("leftShiftedM = {}.", leftShiftedM); return maskAndN | leftShiftedM; }  static int insertMIntoN(int N, int M, int i, int j); static final Logger LOGGER; }