package chapter_5;

public class Insertion {
  public String insertMIntoN(int m, int n, int i, int j) {
    int result = clearBits(n, i, j);
    return Integer.toBinaryString(result | (m << i));
  }

  private int clearBits(int n, int i, int j) {
    int val = Integer.MAX_VALUE >>> (31 - j - 1);
    int val2 = Integer.MAX_VALUE << i;
    int mask = val & val2;
    return n & ~(mask);
  }
}

@@ -254,33 +254,20 @@
 t val = 
-Integer.MAX_VALUE
+~(0)
  %3E%3E%3E (31
@@ -274,12 +274,8 @@
  - j
- - 1
 );%0A 
@@ -292,25 +292,12 @@
 2 = 
-Integer.MAX_VALUE
+~(0)
  %3C%3C 

Use ~0 instead of integer max value, Use Logical right shift which is important here