package main;

class BitManipulator {
    static int insertBitsToPosition(int n, int m, int i, int j) {
        int left = ~0 << j;
        int right = (1 << i-1) - 1;
        int mask = left | right;
        int nCleared = n & mask;
        int mShifted = m << i-1;
        return nCleared | mShifted;
    }
}

@@ -109,197 +109,64 @@
     
-int left = ~0 %3C%3C j;%0A        int right = (1 %3C%3C i-1) - 1;%0A        int mask = left %7C right;%0A        int nCleared = n & mask;%0A        int mShifted = m %3C%3C i-1;%0A        return nCleared %7C mShifted
+return (n & ((~0 %3C%3C j) %7C ((1 %3C%3C i-1) - 1))) %7C (m %3C%3C i-1)
 ;%0A  

Refactor solution for 5.1 to 1-line transofrmation function. Note: it takes less space but almost unreadable for human.