package CH5.Q1;

public class Question {

    int writeBits(int a, int b, int from, int to) {
        int max = ~0;

        // Create a mask int with 0's between from and to.
        // ex. 1111111111000111

        // Note:
        // (1 << 4) = 1000
        // ((1 << 4) - 1) = 111

        // 1's before to.
        int left = max - ((1 << to) -1);
        // 1's after from.
        int right = ((1 << from) - 1);

        // Create the mask.
        int mask = left | right;

        return (a & mask) | (b << from);
    }

}

@@ -35,16 +35,408 @@
 tion %7B%0A%0A
+    /**%0A     * Take two integers a and b.%0A     * Write the bits from b into a in between indices from and to.%0A     *%0A     * ex.%0A     * a = 111111%0A     * b = 000000%0A     * indices:%0A     * from = 2%0A     * to = 4%0A     * result = 001110%0A     *%0A     * @param a First int.%0A     * @param b Second int.%0A     * @param from Start index.%0A     * @param to End index.%0A     * @return Combined int.%0A     */%0A
     int 

Add doc.