Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Binary logarithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Integer rounding=== The binary logarithm can be made into a function from integers and to integers by [[rounding]] it up or down. These two forms of integer binary logarithm are related by this formula: :<math> \lfloor \log_2(n) \rfloor = \lceil \log_2(n + 1) \rceil - 1, \text{ if }n \ge 1.</math><ref name="Warren_2002">{{citation |title=Hacker's Delight |title-link=Hacker's Delight |first=Henry S. |last=Warren Jr. |date=2002 |edition=1st |publisher=[[Addison Wesley]] |isbn=978-0-201-91465-8 |page=215}}</ref> The definition can be extended by defining <math> \lfloor \log_2(0) \rfloor = -1</math>. Extended in this way, this function is related to the [[number of leading zeros]] of the 32-bit unsigned binary representation of {{mvar|x}}, {{math|nlz(''x'')}}. :<math>\lfloor \log_2(n) \rfloor = 31 - \operatorname{nlz}(n).</math><ref name="Warren_2002" /> The integer binary logarithm can be interpreted as the zero-based index of the most significant {{math|1}} bit in the input. In this sense it is the complement of the [[find first set]] operation, which finds the index of the least significant {{math|1}} bit. Many hardware platforms include support for finding the number of leading zeros, or equivalent operations, which can be used to quickly find the binary logarithm. The <code>fls</code> and <code>flsl</code> functions in the [[Linux kernel]]<ref>[https://www.kernel.org/doc/htmldocs/kernel-api/API-fls.html fls], Linux kernel API, [[kernel.org]], retrieved 2010-10-17.</ref> and in some versions of the [[libc]] software library also compute the binary logarithm (rounded up to an integer, plus one).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)