Skip to content

Code for LowestSetBitManipulation added #5574

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

Closed
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Updated the code after reviewing with CI checks
  • Loading branch information
ishanki19-pixel committed Oct 5, 2024
commit 2ab3f9d776cfd3ee8aba67a679c40ecd0ec2f764
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.thealgorithms.bitmanipulation;

public final class LowestSetBit {

/**
* Method to isolate the lowest set bit of a given integer.
* @param n the integer input
* @return the isolated lowest set bit or 0 if n is 0
*/
public int isolateLowestSetBit(int n) {
return n & -n; // Works for both positive and negative
}

/**
* Method to clear the lowest set bit of a given integer.
* @param n the integer input
* @return the integer with the lowest set bit cleared
*/
public int clearLowestSetBit(int n) {
return n & (n - 1);
}
}
Loading