MCPcopy Create free account
hub / github.com/apna-college/Alpha / updateIthBit

Method updateIthBit

5_Bit Manipulation/BitOperations.java:21–33  ·  view source on GitHub ↗
(int n, int i, int val)

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 1

clearIthBitMethod · 0.95

Tested by

no test coverage detected