public static int intFitsIn(final int value) {
        if (value < 0) {
            return 4;
        }

        if (value < (1 << (2 * 8))) {
            if (value < (1 << (1 * 8))) {
                return 1;
            }
            return 2;
        }
        if (value <= (1 << (3 * 8))) {
            return 3;
        }
        return 4;
    }
Check how many bytes is required to store value.

@param value Value which size will be tested.
@return How many bytes are required to store value.
stroom-bytebuffer/src/main/java/stroom/bytebuffer/hbase/ByteBufferUtils.java