public static int getMultiBit(int v, int position, int bitSize) {
        int shift = position;

        int mask = 0;
        for (int i = 0; i < bitSize; i++) {
            mask |= ((v & (1 << shift)) >>> position);
            shift++;
        }
        return mask;
    }
Returns v, with the bit at position set to 1 or 0 depending on value.
commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/BitFieldUtils.java