Created
July 19, 2015 20:54
-
-
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
This file contains 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
#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