Skip to content

Commit a67fd72

Browse files
authored
Merge pull request #4 from lukasb1b/final-BitOperator
Final bit operator
2 parents 16e230c + 3de87ac commit a67fd72

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/main/java/com/thealgorithms/bitmanipulation/SingleBitOperators.java renamed to src/main/java/com/thealgorithms/bitmanipulation/SingleBitOperator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44
* Author: lukasb1b (https://github.com/lukasb1b)
55
*/
66

7-
public class SingleBitOperators {
7+
public class final SingleBitOperators {
88
/**
99
* Flip the bit at position 'bit' in 'num'
1010
*/
11-
public static int flipBit(int num, int bit) {
11+
public static int flipBit(final int num, final int bit) {
1212
return num ^ (1 << bit);
1313
}
1414
/**
1515
* Set the bit at position 'bit' to 1 in the 'num' variable
1616
*/
17-
public static int setBit(int num, int bit) {
17+
public static int setBit(final int num,final int bit) {
1818
return num | (1 << bit);
1919
}
2020
/**
2121
* Clears the bit located at 'bit' from 'num'
2222
*/
23-
public static int clearBit(int num, int bit) {
23+
public static int clearBit(final int num,final int bit) {
2424
return num & ~(1 << bit);
2525
}
2626
/**
2727
* Get the bit located at 'bit' from 'num'
2828
*/
29-
public static int getBit(int num, int bit) {
29+
public static int getBit(final int num,final int bit) {
3030
return ((num >> bit) & 1);
3131
}
3232
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
package com.thealgorithms.bitmanipulation;
22

3-
import static org.junit.jupiter.api.Assertions.*;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
44

55
import org.junit.jupiter.api.Test;
66

77
public class SingleBitOperatorTest {
88

99
@Test
1010
public void flipBitTest() {
11-
assertEquals(1, SingleBitOperators.flipBit(3, 1));
12-
assertEquals(11, SingleBitOperators.flipBit(3, 3));
11+
assertEquals(1, SingleBitOperator.flipBit(3, 1));
12+
assertEquals(11, SingleBitOperator.flipBit(3, 3));
1313
}
1414

1515
@Test
1616
public void setBitTest() {
17-
assertEquals(5, SingleBitOperators.setBit(4, 0));
18-
assertEquals(4, SingleBitOperators.setBit(4, 2));
17+
assertEquals(5, SingleBitOperator.setBit(4, 0));
18+
assertEquals(4, SingleBitOperator.setBit(4, 2));
1919
}
2020

2121
@Test
2222
public void clearBitTest() {
23-
assertEquals(5, SingleBitOperators.clearBit(7, 1));
24-
assertEquals(5, SingleBitOperators.clearBit(5, 1));
23+
assertEquals(5, SingleBitOperator.clearBit(7, 1));
24+
assertEquals(5, SingleBitOperator.clearBit(5, 1));
2525
}
2626

2727
@Test
2828
public void getBitTest() {
29-
assertEquals(0, SingleBitOperators.getBit(6, 0));
30-
assertEquals(1, SingleBitOperators.getBit(7, 1));
29+
assertEquals(0, SingleBitOperator.getBit(6, 0));
30+
assertEquals(1, SingleBitOperator.getBit(7, 1));
3131
}
3232
}

0 commit comments

Comments
 (0)