Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power_of_2.cpp #174

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Power_of_2.cpp #174

wants to merge 1 commit into from

Conversation

ADARSH-863
Copy link

This C++ program, authored by ADARSH, efficiently checks whether a user-inputted number is a power of 2 or not using bitwise manipulation. It employs the bitwise AND operation with n and n - 1 to clear the rightmost set bit. If the result is 0 and n is not zero, the program determines that the input number has only one bit set, indicating it is a power of 2. The program prompts the user for a number, performs this check, and then outputs either "It's a power of 2." or "It's not a power of 2." based on the evaluation, providing an immediate and clear response about the nature of the input number.

This C++ program, authored by ADARSH, efficiently checks whether a user-inputted number is a power of 2 or not using bitwise manipulation. It employs the bitwise AND operation with n and n - 1 to clear the rightmost set bit. If the result is 0 and n is not zero, the program determines that the input number has only one bit set, indicating it is a power of 2. The program prompts the user for a number, performs this check, and then outputs either "It's a power of 2." or "It's not a power of 2." based on the evaluation, providing an immediate and clear response about the nature of the input number.
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.

1 participant