How I would do FizzBuzz
#include <cstdint>
#include <cstdio>
//
// only accurate for n up to 99999999
//
// only accurate on little-endian machines
//
void fb(int64_t n, char *out) {
*(int64_t *)out =
(n * 0xaaaaaaaaaaaaaaab < 0x5555555555555556) * 0x000000007a7a6946 ^
(n * 0xcccccccccccccccd < 0x3333333333333334) * 0x000000007a7a7542 ^
(n * 0xeeeeeeeeeeeeeeef < 0x1111111111111112) * 0x7a7a75427a7a7542;
if (*out == 0) {
sprintf(out, "%lld", n);
}
}
int main(int argc, char **argv) {
char s[9] = {0};
for (int i = 1; i <= 100; i++) {
fb(i, s);
printf("%s\n", s);
}
return 0;
}
See Database of 2-adic Integers
Inspired by https://gynvael.coldwind.pl/n/c_cpp_number_to_binary_string_01011010
Hint: “FizzBuzz” has 8 letters