Skip to content

Conversation

@sunmisc
Copy link

@sunmisc sunmisc commented Apr 12, 2023

use a faster calculation of the power of two closest to input - 1, which uses bitwise operations at the hardware level (Intrinsic)

@wolfieboy09
Copy link

What about return (-1 >>> Integer.numberOfLeadingZeros(input - 1)) + 1;? Makes the function into one line

@sunmisc
Copy link
Author

sunmisc commented Mar 29, 2025

What about return (-1 >>> Integer.numberOfLeadingZeros(input - 1)) + 1;? Makes the function into one line

Yeah, thanks, that's better.

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.

3 participants