MergeBinaryNumbers { public int merge(int n, int m, int i, int j) { int maskFullOfOnes = ~0; int fullOfOnesBeforeJ = maskFullOfOnes << (j + 1); int fullOfOnesAfterI = ((1 << i) - 1); int allOnesExceptIandJ = fullOfOnesBeforeJ | fullOfOnesAfterI; int clearBitsBetweenIandJ = n & allOnesExceptIandJ; int moveMToTheCorrectPosition = m << i; return clearBitsBetweenIandJ | moveMToTheCorrectPosition; }  int merge(int n, int m, int i, int j);  }
@Test public void shouldMergeBinaryNumbersUsingPointers() { int n = 1024; int m = 19; int result = mergeBinaryNumbers.merge(n, m, 2, 6); int expectedResult = 1100; assertEquals(expectedResult, result); }