Skip to content

michael105/Bit-Twiddling-Hacks-Collection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

A single C header files containing functions with different bit twiddling hacks and a short explanation. I've put them together for myself as a cheatsheet and to play around with them. If you know any hacks not included, just submit a PR, or if you encounter any wrong stuff or a typo!

Short hack assortment:

  • Number multiplication, division
  • Even, odd and power checks
  • Set, clear and flip bits
  • Insert and extract bitfields into words
  • Swapping without temporaries
  • Size comparison: min() and max() functions without branching
  • Modular additions
  • Power rounding
  • Significant masking
  • Logbase2 of power2 calculation using deBruijin sequence
  • Fast inverse sqrt
  • Bit reversion
  • Masked color operations
  • Division and multiplication by 10

About

A single C file with bitwise hacks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%