class Bytes {

    public static int normalize(int i, int bitCount) {
        int max = 0xffffffff >>> (32 - bitCount);
        if (i > max)
            throw new IllegalArgumentException("The integer cannot fit to bit boundaries.");
        if (i > (max >>> 1))
            return i - (max + 1);
        else
            return i;
    }

}