4 ms·
Here's a fancier, slightly less-magic, version. How to compile is left as an exercise for the reader (hint: Haswell or newer, requires BMI2 instruction set):
by seiji 11y ago
Here's a fancier, slightly less-magic, version. How to compile is left as an exercise for the reader (hint: Haswell or newer, requires BMI2 instruction set):
void toBinary(uint8_t byte) {
uint64_t zeroes = *(uint64_t *)"00000000";
uint64_t resultStr =
zeroes | __builtin_bswap64(_pdep_u64(byte, 0x0101010101010101ULL));
printf("hello: %.*s\n", 8, (char *)&resultStr);
}
- acz 11y agoThis really reminds me of the old demoscene diskmag Hugi article about adding 16 bit colors (without MMX). http://www.hugi.scene.org/online/hugi18/cobrad.htm http://www.hugi.scene.org/online/hugi18/cobrad.htm