(int n, int i, int val)
| 19 | |
| 20 | //Update ith Bit |
| 21 | public static int updateIthBit(int n, int i, int val) { |
| 22 | //Method1 |
| 23 | // if(val == 0) { |
| 24 | // return n & (~(1<<i)); |
| 25 | // } else { |
| 26 | // return n | (1<<i); |
| 27 | // } |
| 28 | |
| 29 | //Method2 |
| 30 | n = clearIthBit(n, i); |
| 31 | int bitMask = val<<i; |
| 32 | return n | bitMask; |
| 33 | } |
| 34 | |
| 35 | //Clear Last i Bits |
| 36 | public static int clearLastIbits(int n, int i) { |
nothing calls this directly
no test coverage detected