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

Add largest power of 2 less than or equal to a given number #9347

Closed
siddwarr opened this issue Oct 2, 2023 · 1 comment · Fixed by #9374
Closed

Add largest power of 2 less than or equal to a given number #9347

siddwarr opened this issue Oct 2, 2023 · 1 comment · Fixed by #9374
Labels
enhancement This PR modified some existing files

Comments

@siddwarr
Copy link
Contributor

siddwarr commented Oct 2, 2023

Feature description

This can be done by left-shifting the given number and stopping when you reach the first set bit. And then you can find the largest power of two by finding the difference between the length of the given number when converting it to binary form and the no of times you had to shift to find the first set bit.

@tusharsharma5347

This comment was marked as off-topic.

@siddwarr siddwarr mentioned this issue Oct 2, 2023
14 tasks
This was referenced Oct 4, 2023
@ChrisO345 ChrisO345 mentioned this issue Oct 4, 2023
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
2 participants