-
Notifications
You must be signed in to change notification settings - Fork 20k
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
Add SingleBitOperations #4415
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4ad886f
SingleBitOperators
lukasb1b c875d6f
Tests
lukasb1b 267f552
Update SingleBitOperatorTest.java
lukasb1b 57b1f0d
Update SingleBitOperators.java
lukasb1b 14f084f
Update SingleBitOperators.java
lukasb1b 8492bee
Update SingleBitOperators.java
lukasb1b 07581e2
Update SingleBitOperatorTest.java
lukasb1b 5cc6081
deliting files
lukasb1b 0edddf4
Update SingleBitOperators.java
lukasb1b 921ad5e
Update SingleBitOperatorTest.java
lukasb1b 3e0d113
Update SingleBitOperators.java
lukasb1b b1d28c5
Update SingleBitOperators.java
lukasb1b 20f7d70
Update SingleBitOperatorTest.java
lukasb1b 16e230c
Update SingleBitOperatorTest.java
lukasb1b 0f339b1
Update and rename SingleBitOperators.java to SingleBitOperator.java
lukasb1b 3de87ac
Update SingleBitOperatorTest.java
lukasb1b a67fd72
Merge pull request #4 from lukasb1b/final-BitOperator
lukasb1b 5d5e8cb
Update SingleBitOperator.java
lukasb1b 04db0be
Update SingleBitOperator.java
lukasb1b 4b8c4d3
Update SingleBitOperator.java
lukasb1b 034273d
style: declare private default constructor
vil02 931310e
Merge branch 'master' into SingleBitOperators
vil02 3994164
fix: remove `SetBitTest.java`
vil02 5d0cc53
Update and rename SingleBitOperator.java to SingleBitOperations.java
lukasb1b 5ccfe68
Update SingleBitOperatorTest.java
lukasb1b 5d9d5e7
Update SingleBitOperations.java
lukasb1b dcb41ab
Update and rename SingleBitOperatorTest.java to SingleBitOperationsTe…
lukasb1b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
src/main/java/com/thealgorithms/bitmanipulation/ClearBit.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/main/java/com/thealgorithms/bitmanipulation/SetBit.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
src/main/java/com/thealgorithms/bitmanipulation/SingleBitOperator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.thealgorithms.bitmanipulation; | ||
|
||
/* | ||
* Author: lukasb1b (https://github.com/lukasb1b) | ||
*/ | ||
|
||
public final class 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); | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
src/test/java/com/thealgorithms/bitmanipulation/ClearBitTest.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/test/java/com/thealgorithms/bitmanipulation/SetBit.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
src/test/java/com/thealgorithms/bitmanipulation/SingleBitOperatorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.