Add Clear Bit (#4355)
This commit is contained in:
parent
29a864b5b3
commit
fbef4023d5
@ -0,0 +1,11 @@
|
|||||||
|
package com.thealgorithms.bitmanipulation;
|
||||||
|
/**
|
||||||
|
* Clears the bit located at clear from num
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ClearBit {
|
||||||
|
public static int clearBit(int num, int clear) {
|
||||||
|
int mask = ~(1 << clear);
|
||||||
|
return num & mask;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.thealgorithms.bitmanipulation;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class ClearBitTest {
|
||||||
|
@Test
|
||||||
|
public void clearBitTest() {
|
||||||
|
assertEquals(5, ClearBit.clearBit(7, 1));
|
||||||
|
assertEquals(5, ClearBit.clearBit(5, 1));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user