Comment

Comment by AnotherGoodName

I noticed the following is in the middle of the article with no context that no one else is mentioning:

    unsigned average(unsigned a, unsigned b)
    {
        return (a & b) + (a ^ b) / 2;
    }
A quick sanity check of this

23 & 21 = 21

23 ^ 21 = 2

21 + 2 / 2 = 22 (order of operations)

I wonder why this is there. It seems the best solution but no one else is mentioning it. It also has no context near it. Nor is it stated correctly. It's just there on it's own.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton