-
Notifications
You must be signed in to change notification settings - Fork 20k
Set bit #4356
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
Set bit #4356
Conversation
lukasb1b
commented
Sep 7, 2023
- I have read CONTRIBUTING.md.
- This pull request is all my own work -- I have not plagiarized it.
- All filenames are in PascalCase.
- All functions and variable names follow Java naming conventions.
- All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
Issue #4350 |
I want to add to the Issue that SetBit is already implemented and ClearBit is in other pullrequest |
@vil02 @BamaCharanChhandogi please review |
Hi, @lukasb1b, |
@siriak, @BamaCharanChhandogi, @lukasb1b: please have a look at my comment in the corresponding issue. |
* Returns the value of bit from num located at get | ||
*/ | ||
|
||
public class GetBit { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very good start for the BitArray
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding this as-is and consolidating algorithms into a data structure in a following PR. There are already some other functions implemented in this manner and, as you have mentioned, there are open questions about the design of this BitArray.
@lukasb1b will you be able to consolidate these bit functions into a BitArray in the next PR? If no, somebody else could pick up this task.
In the meantime, we can discuss what we want to use as an underlying type.
public class GetBit { | ||
public static int getBit(int num, int get) { | ||
return (num >> get) & 1; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case such functionality will be needed.
public class GetBit { | |
public static int getBit(int num, int get) { | |
return (num >> get) & 1; | |
} | |
} | |
public final class GetBit { | |
private GetBit() { | |
} | |
public static boolean get(final int data, final int pos) { | |
if (pos < 0 || pos >= Integer.SIZE) { | |
throw new ArrayIndexOutOfBoundsException(); | |
} | |
return ((data >> pos) & 1) > 0; | |
} | |
} |
I am not sure what is the best way to make it accept any IntegralType
- I could not find a convenient way how to get the SIZE
.
Please add tests for the missing branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stick to int32 then
I can add all the SingleBit functions in onte but at first i think we should have a solution for the Problem i personally think a bit array is not as functional but we could do it generic like in the example below. And we add another function for arrays. public class GetBit{
|
As suggested before, let stick to I agree that it is a good idea to have one utilitiy class like |
Hi I closed the request so you can implement it I dont get how you want to do it so I think its quicker if you do it yourself |