Skip to content

Conversation

@krishna-medapati
Copy link
Contributor

Fixes #6940

Description

Added a utility class to check if a number is a power of four using efficient bit manipulation.

Implementation Details

  • Uses bit manipulation to check if a number is a power of four in O(1) time
  • Verifies the number is a power of two: (n & (n-1)) == 0
  • Checks if the set bit is at an even position using mask 0x55555555
  • Follows the existing code style and structure of the repository

Changes Made

  • Created PowerOfFour.java with isPowerOfFour() method
  • Added comprehensive unit tests in PowerOfFourTest.java
  • Included JavaDoc documentation

Testing

All test cases pass:

  • Powers of four: 1, 4, 16, 64, 256, 1024
  • Non-powers of four: 2, 3, 5, 8, 15, 32
  • Edge cases: 0, -1, -4

- Implements isPowerOfFour method using bit manipulation
- Checks if number is power of two and has bit at even position
- Includes comprehensive unit tests
- Fixes TheAlgorithms#6940
@codecov-commenter
Copy link

codecov-commenter commented Nov 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.34%. Comparing base (a008cc2) to head (5fb478e).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7065      +/-   ##
============================================
+ Coverage     78.33%   78.34%   +0.01%     
- Complexity     6670     6677       +7     
============================================
  Files           753      754       +1     
  Lines         22185    22190       +5     
  Branches       4356     4359       +3     
============================================
+ Hits          17378    17385       +7     
+ Misses         4107     4106       -1     
+ Partials        700      699       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants