News for hackers. Stuff that matters.
Re:Finding the average of two unsigned integers without over... by dheera on Monday February 07, 2022 @10:31PM (#30254609)
Why not just

   (a >> 1) + (b >> 1) + (a & 1) & (b & 1)
Re:Finding the average of two unsigned integers without over... by dreamcompiler on Monday February 07, 2022 @11:05PM (#30254798)
That's the "patented solution" referred to in the article.
Re:Finding the average of two unsigned integers without over... by andi999 on Tuesday February 08, 2022 @03:48AM (#30256180)
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.
Re:Finding the average of two unsigned integers without over... by dheera on Tuesday February 08, 2022 @04:15AM (#30256347)
Don't read the article, and you would never know it's patented.
Re:Finding the average of two unsigned integers without over... by Dylan16807 on Tuesday February 08, 2022 @12:00AM (#30255052)
"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.
Re:Finding the average of two unsigned integers without over... by rustybolt on Tuesday February 08, 2022 @01:47AM (#30255596)
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.