Skip to content
Closed
Changes from all commits
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
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);
}
}