I was given this question in an interview to describe the output in comments.
unsigned int d2(unsigned int a)
{
__int64 q = (__int64)a * 0x0AAAAAAAB; // (2^33+1) / 3
return (unsigned int)(q >> 33);
}
I have checked other questions in Stackoverflow related to division by 3 but none seems so fast and small. Can anybody help me in explaining how the function is giving the output written in comments ?