public int solutionForBinaryGap(int N) {
        // write your code in Java SE 8
        int max = 0, count = 0;

        while (N > 0) {
            if ((N & 1) == 1) {
                break;
            }
            N = N >> 1;
        }

        while (N > 0) {
            if ((N & 1) == 0) {
                count++;
                max = Math.max(count, max);
            } else {
                count = 0;
            }
            N = N >> 1;
        }
        return max;
    }