This is one of my favorite sites on the internet: https://graphics.stanford.edu/~seander/bithacks.html
I recommend Matt Godbolt's Talk(s) about compiler cleverness: https://www.youtube.com/watch?v=bSkpMdDe4g4 (see the 30 minute mark for the multiplication example)
> This is one of my favorite sites on the internet: https://graphics.stanford.edu/~seander/bithacks.html
Yes - I also enjoyed the book "Hacker's Delight", but haven't got round to reading the second edition yet.
But I think what you're aiming to say is:
r << 5 | r << 2 | r >> 1 amounts (because r is constrained to three bits) to being the same as
r << 5 + r << 2 + r >> 1
And r << 5 is r * 32, r << 2 is r * 4, and r >> 1 is floor(r / 2)
So the whole thing is
r * 32 + r * 4 + floor(r * 0.5)
which is the same as
floor(r * 32 + r * 4 + r * 0.5)
or
floor(r * 36.5)