Anonymous

Not logged in

  • Log in
WikiCoder

Bit Twiddling Hacks

From WikiCoder

Namespaces

  • Page
  • Discussion

More

  • More

Page actions

  • Read
  • View source
  • History
  • Computing the sign of an integer
  • Detect if two integers have opposite signs
  • Compute the integer absolute value (abs) without branching
  • Compute the minimum (min) or maximum (max) of two integers without branching
  • Determining if an integer is a power of 2
  • Sign Extending
  • Conditionally set or clear bits without branching
  • Conditionally negate a value without branching
  • Merge bits from two values according to a mask
  • Counting bits set
  • Computing parity (1 if an odd number of bits set, 0 otherwise)
  • Swapping Values
  • Reversing bit sequences
  • Modulus division (aka computing remainders)
  • Finding integer log base 2 of an integer (aka the position of the highest bit set)
  • Finding integer log base 10 of an integer
  • Find integer log base 2 of a 32-bit IEEE float
  • Find integer log base 2 of the pow(2, r)-root of a 32-bit IEEE float (for unsigned integer r)
  • Counting consecutive trailing zero bits (or finding bit indices)
  • Round up to the next highest power of 2 by float casting
  • Round up to the next highest power of 2
  • Interleaving bits (aka computing Morton Numbers)
  • Testing for ranges of bytes in a word (and counting occurances found)
  • Compute the lexicographically next bit permutation
  • log2f approximation
Retrieved from "http://wikicoder.org/index.php?title=Bit_Twiddling_Hacks&oldid=570"

Navigation

Navigation

  • Main page
  • Recent changes
  • Random page
  • Help about MediaWiki

Wiki tools

Wiki tools

  • Special pages
  • Cite this page

Page tools

Page tools

    Userpage tools

      More

      • What links here
      • Related changes
      • Permanent link
      • Page information
      • Page logs
      Powered by MediaWiki
      • This page was last edited on 26 July 2020, at 11:21.
      • Privacy policy
      • About WikiCoder
      • Disclaimers