Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Program {
- public static boolean containsBit(int mask, int el) {
- return ((mask & (1 << el)) != 0) ? true : false;
- }
- public static int insertBit(int mask, int el) {
- return (mask | (1 << el));
- }
- public static int eraseBit(int mask, int el) {
- return (mask & ~(1 << el));
- }
- public static int changeBit(int mask, int el) {
- return (mask ^ (1 << el));
- }
- public static void main(String[] args) {
- int mask = 0;
- mask = insertBit(mask, 3);
- mask = insertBit(mask, 5);
- mask = insertBit(mask, 10);
- mask = eraseBit(mask, 5);
- mask = changeBit(mask, 3);
- mask = changeBit(mask, 0);
- for (int i = 0; i < 32; i++) {
- System.out.println("Bit[" + i + "] = " + containsBit(mask, i));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement