public final class Bitfield {
private Bitfield() {}
// ********************************************************************
// * TEST
// ********************************************************************
public static boolean testBit(final int pos, final int bitfield) {
return (bitfield & (1 << pos)) == (1 << pos);
}
public static boolean testNum(final int num, final int bitfield) {
return (bitfield & num) == num;
}
// ********************************************************************
// * SET
// ********************************************************************
public static int setBit(final int pos, final int bitfield) {
return bitfield | (1 << pos);
}
public static int addNum(final int number, final int bitfield) {
return bitfield | number;
}
// ********************************************************************
// * CLEAR
// ********************************************************************
public static int clearBit(final int pos, final int bitfield) {
return bitfield ^ (1 << pos);
}
public static int clearNum(final int num, final int bitfield) {
return bitfield ^ num;
}
}