public class Main {
    public static void main(String[] args) {
        arrayOutput(0x01000000, 0x02000004);
        arrayOutput(0x03000000, 0x04000004);
        arrayOutput(0x07000000, 0x08000004);
        arrayOutput(0x0F000000, 0x10000004);
        arrayOutput(0x1F000000, 0x20000004);
        arrayOutput(0x3F000000, 0x40000004);
        System.out.println();

        for (int loop = 0; loop < 5; loop++) {
            arrayInput(0x200000);
        }
    }

    static void arrayOutput(int from, int to) {
        int[] output = new int[to - from];
        for (int i = from; i < to; i++) {
            output[i - from] = Integer.numberOfLeadingZeros(i);
        }

        for (int i = from; i < to; i++) {
            int nlz = Integer.numberOfLeadingZeros(i);
            if (nlz != output[i - from]) {
                System.out.printf("0x%08X: expected=%d actual=%d%n", i, nlz, output[i - from]);
            }
        }
    }

    static void arrayInput(int size) {
        int expected = 0;
        for (int i = 0; i < size; i++)
            expected += Integer.numberOfLeadingZeros(-1 >>> i);

        int[] input = new int[size];
        java.util.Arrays.setAll(input, i -> -1 >>> i);
        int actual = 0;
        for (int i = 0; i < size; i++)
            actual += Integer.numberOfLeadingZeros(input[i]);

        System.out.printf("expected=%d, actual=%d%n", expected, actual);
    }
}