Skip to content

Add SingleBitOperations #4415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4ad886f
SingleBitOperators
lukasb1b Sep 27, 2023
c875d6f
Tests
lukasb1b Sep 27, 2023
267f552
Update SingleBitOperatorTest.java
lukasb1b Sep 27, 2023
57b1f0d
Update SingleBitOperators.java
lukasb1b Sep 27, 2023
14f084f
Update SingleBitOperators.java
lukasb1b Sep 27, 2023
8492bee
Update SingleBitOperators.java
lukasb1b Sep 27, 2023
07581e2
Update SingleBitOperatorTest.java
lukasb1b Sep 27, 2023
5cc6081
deliting files
lukasb1b Sep 27, 2023
0edddf4
Update SingleBitOperators.java
lukasb1b Sep 27, 2023
921ad5e
Update SingleBitOperatorTest.java
lukasb1b Sep 27, 2023
3e0d113
Update SingleBitOperators.java
lukasb1b Sep 27, 2023
b1d28c5
Update SingleBitOperators.java
lukasb1b Sep 27, 2023
20f7d70
Update SingleBitOperatorTest.java
lukasb1b Sep 27, 2023
16e230c
Update SingleBitOperatorTest.java
lukasb1b Sep 27, 2023
0f339b1
Update and rename SingleBitOperators.java to SingleBitOperator.java
lukasb1b Sep 28, 2023
3de87ac
Update SingleBitOperatorTest.java
lukasb1b Sep 28, 2023
a67fd72
Merge pull request #4 from lukasb1b/final-BitOperator
lukasb1b Sep 28, 2023
5d5e8cb
Update SingleBitOperator.java
lukasb1b Sep 28, 2023
04db0be
Update SingleBitOperator.java
lukasb1b Sep 28, 2023
4b8c4d3
Update SingleBitOperator.java
lukasb1b Sep 28, 2023
034273d
style: declare private default constructor
vil02 Sep 28, 2023
931310e
Merge branch 'master' into SingleBitOperators
vil02 Sep 28, 2023
3994164
fix: remove `SetBitTest.java`
vil02 Sep 28, 2023
5d0cc53
Update and rename SingleBitOperator.java to SingleBitOperations.java
lukasb1b Sep 30, 2023
5ccfe68
Update SingleBitOperatorTest.java
lukasb1b Sep 30, 2023
5d9d5e7
Update SingleBitOperations.java
lukasb1b Sep 30, 2023
dcb41ab
Update and rename SingleBitOperatorTest.java to SingleBitOperationsTe…
lukasb1b Sep 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/main/java/com/thealgorithms/bitmanipulation/ClearBit.java

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/com/thealgorithms/bitmanipulation/SetBit.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.thealgorithms.bitmanipulation;

/*
* Author: lukasb1b (https://github.com/lukasb1b)
*/

public final class SingleBitOperator {
private SingleBitOperator() {
}
/**
* Flip the bit at position 'bit' in 'num'
*/
public static int flipBit(final int num, final int bit) {
return num ^ (1 << bit);
}
/**
* Set the bit at position 'bit' to 1 in the 'num' variable
*/
public static int setBit(final int num, final int bit) {
return num | (1 << bit);
}
/**
* Clears the bit located at 'bit' from 'num'
*/
public static int clearBit(final int num, final int bit) {
return num & ~(1 << bit);
}
/**
* Get the bit located at 'bit' from 'num'
*/
public static int getBit(final int num, final int bit) {
return ((num >> bit) & 1);
}
}

This file was deleted.

13 changes: 0 additions & 13 deletions src/test/java/com/thealgorithms/bitmanipulation/SetBitTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.thealgorithms.bitmanipulation;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class SingleBitOperatorTest {

@Test
public void flipBitTest() {
assertEquals(1, SingleBitOperator.flipBit(3, 1));
assertEquals(11, SingleBitOperator.flipBit(3, 3));
}

@Test
public void setBitTest() {
assertEquals(5, SingleBitOperator.setBit(4, 0));
assertEquals(4, SingleBitOperator.setBit(4, 2));
}

@Test
public void clearBitTest() {
assertEquals(5, SingleBitOperator.clearBit(7, 1));
assertEquals(5, SingleBitOperator.clearBit(5, 1));
}

@Test
public void getBitTest() {
assertEquals(0, SingleBitOperator.getBit(6, 0));
assertEquals(1, SingleBitOperator.getBit(7, 1));
}
}