From d402115d46c1d1dac6df400b0170fd985a14e6a2 Mon Sep 17 00:00:00 2001 From: ishanki19-pixel Date: Sat, 5 Oct 2024 08:32:01 +0530 Subject: [PATCH 1/4] Code for LowestSetBitManipulation added --- .../bitmanipulation/LowestSetBitManipulation.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/com/thealgorithms/bitmanipulation/LowestSetBitManipulation.java diff --git a/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBitManipulation.java b/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBitManipulation.java new file mode 100644 index 000000000000..863c6ed9892a --- /dev/null +++ b/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBitManipulation.java @@ -0,0 +1,13 @@ +public class LowestSetBit { + + // Method to isolate the lowest set bit + public int isolateLowestSetBit(int n) { + if (n == 0) return 0; // Special case for 0 + return n & -n; + } + + // Method to clear the lowest set bit + public int clearLowestSetBit(int n) { + return n & (n - 1); + } +} From 2ab3f9d776cfd3ee8aba67a679c40ecd0ec2f764 Mon Sep 17 00:00:00 2001 From: ishanki19-pixel Date: Sat, 5 Oct 2024 09:10:17 +0530 Subject: [PATCH 2/4] Updated the code after reviewing with CI checks --- .../bitmanipulation/LowestSetBit.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java diff --git a/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java b/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java new file mode 100644 index 000000000000..001690a33500 --- /dev/null +++ b/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java @@ -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); + } +} From 7a29ef2f05ed5470b62ce327bc70ffb5f91577ff Mon Sep 17 00:00:00 2001 From: ishanki19-pixel Date: Sat, 5 Oct 2024 09:17:23 +0530 Subject: [PATCH 3/4] Ensure all changes are committed --- .../bitmanipulation/LowestSetBitManipulation.java | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/main/java/com/thealgorithms/bitmanipulation/LowestSetBitManipulation.java diff --git a/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBitManipulation.java b/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBitManipulation.java deleted file mode 100644 index 863c6ed9892a..000000000000 --- a/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBitManipulation.java +++ /dev/null @@ -1,13 +0,0 @@ -public class LowestSetBit { - - // Method to isolate the lowest set bit - public int isolateLowestSetBit(int n) { - if (n == 0) return 0; // Special case for 0 - return n & -n; - } - - // Method to clear the lowest set bit - public int clearLowestSetBit(int n) { - return n & (n - 1); - } -} From e2398ba41573d19789ce49c0a28b1b54a027e544 Mon Sep 17 00:00:00 2001 From: ishanki19-pixel Date: Sat, 5 Oct 2024 09:18:08 +0530 Subject: [PATCH 4/4] Trigger CI build