Y
Hacker News
new
|
ask
|
show
|
jobs
by
dheera
1587 days ago
Why not just
(a >> 1) + (b >> 1) + (a & 1) & (b & 1)
2 comments
dreamcompiler
1587 days ago
That's the "patented solution" referred to in the article.
link
andi999
1587 days ago
Which is shocking to me, since this is the solution which jumps immediately to mind (and usually patents should be above that line). I could understand if the next solution was patented, but not this one.
link
dheera
1587 days ago
Don't read the article, and you would never know it's patented.
link
Dylan16807
1587 days ago
"just"? That's 2 additions, 2 shifts, and 2-3 bitwise operations, while the other method is 1 addition, 1 shift, and 2 bitwise operations.
link
rustybolt
1587 days ago
I would think optimizing compilers can optimize this expression to the one in the article, but I tried it on godbolt and they don't.
link