Skip to content

Instantly share code, notes, and snippets.

@pallas
Created July 19, 2015 20:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pallas/4a9e26477501048dc2b8 to your computer and use it in GitHub Desktop.
C++ template to generate a magic mask with alternating runs of 0s & 1s
#include <cstdint>
template <typename T>
inline T magic_mask(int_fast8_t n) {
T base = T(1)<<(int_fast16_t(1)<<n);
return (~T(0))/(base*base-1)*(base-1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment