-
Couldn't load subscription status.
- Fork 20.7k
Open
Labels
Description
What would you like to Propose?
Title: Add Bit Manipulation Algorithm to Check if a Number is Power of Four
🧠 Overview
Contribute an algorithm to determine whether a given integer is a power of four using efficient bitwise operations instead of loops or recursion.
📂 Implementation Details
- Folder:
src/main/java/com/thealgorithms/bitmanipulation/ - Filename:
IsPowerOfFour.java - Approach:
- Use properties of powers of two plus mask check:
(n & (n - 1)) == 0 && (n & 0xAAAAAAAA) == 0.
- Use properties of powers of two plus mask check:
✅ Expected Deliverables
- Efficient O(1) solution using bitwise math.
- Unit tests with edge cases (0, negative numbers).
- Explanation comments of binary logic.
🧑💻 Additional Notes
This lightweight algorithm deepens understanding of bitwise pattern analysis.
Issue details
🧠 Overview
Contribute an algorithm to determine whether a given integer is a power of four using efficient bitwise operations instead of loops or recursion.
Additional Information
No response