Created
September 24, 2022 04:19
-
-
Save frangio/74dc44635aa99cc603e9d6f048e54e87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nlz(uint x) pure returns (uint n) { | |
uint y; | |
n = 256; | |
y = x >> 128; if (y != 0) { n = n - 128; x = y; } | |
y = x >> 64; if (y != 0) { n = n - 64; x = y; } | |
y = x >> 32; if (y != 0) { n = n - 32; x = y; } | |
y = x >> 16; if (y != 0) { n = n - 16; x = y; } | |
y = x >> 8; if (y != 0) { n = n - 8; x = y; } | |
y = x >> 4; if (y != 0) { n = n - 4; x = y; } | |
y = x >> 2; if (y != 0) { n = n - 2; x = y; } | |
y = x >> 1; if (y != 0) return n - 2; | |
return n - x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment