Skip to content

Commit fbef402

Browse files
authored
Add Clear Bit (TheAlgorithms#4355)
1 parent 29a864b commit fbef402

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.thealgorithms.bitmanipulation;
2+
/**
3+
* Clears the bit located at clear from num
4+
*/
5+
6+
public class ClearBit {
7+
public static int clearBit(int num, int clear) {
8+
int mask = ~(1 << clear);
9+
return num & mask;
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.thealgorithms.bitmanipulation;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class ClearBitTest {
8+
@Test
9+
public void clearBitTest() {
10+
assertEquals(5, ClearBit.clearBit(7, 1));
11+
assertEquals(5, ClearBit.clearBit(5, 1));
12+
}
13+
}

0 commit comments

Comments
 (0)