What do you think this outputs?
unsigned char c = 241;
long bits = (c * 01001001001ULL & 042104210421ULL) % 017;
printf("Bits = %lu\n",bits);
Remarkably it calculates the number of bits in c and should output “Bits = 5”.
If you don’t believe me, try this program to show all 256 values and the count. If you use c in the for loop instead of i, it never finishes. Well not with Visual C++ 2019!
#include <stdio.h>
int main()
{
for (int i = 0; i < 256; i++){
unsigned char c = i % 256;
long bits = (c * 01001001001ULL & 042104210421ULL) % 017;
printf("c %d #Bits = %lu\n",c, bits);
}
return 0;
}
You can try this out online on one of the various online C compilers.
Here’s it on repl.it.
(Visited 388 times, 1 visits today)