Skip to content

[FEATURE REQUEST] Power of Four Check (Bit Manipulation) #6940

@Shewale41

Description

@Shewale41

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.

✅ 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions