News for hackers. Stuff that matters.
Re:Finding the average of two unsigned integers without over... by ggrrhh_ta on Tuesday February 08, 2022 @07:41AM (#30257720)
The explanation seems to work even in base 10.

Let's do the average of 85 and 95. The leftmost digit of both is equal, so we leave it: X5 The "xor"/2 is the sum of the non equal digits divided by 2 (respecting their powers): (8+9)10 = (17)10 = 85 Now, we add them: 5 + 85 = 90 (which is the average of 85 and 95).

Let's take now 87 and 89: The rightmost digits are equal: 8X We do the 'xor'/2 for the left most: (7+9)/2 = 8 8X + 8 = 88

Let me know if there are some examples for which it would fail (I only spent a minute to test if the explanation extends to other bases).

Re:Finding the average of two unsigned integers without over... by remram on Tuesday February 08, 2022 @11:33AM (#30260489)
The average of 15 and 30 is not 22. The average of 51 and 03 is not 22.