Skip to content

Instantly share code, notes, and snippets.

@pallas
Created Jul 19, 2015
Embed
What would you like to do?
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