I understand your calculation, but it results in a value of over 8 million, while my empirical calculated value is only around 29 thousand. That's a pretty big difference.
The thing is, in addition to ab being the same as ba, the components for the average color are calculated as (a + b) / 2, so you things like this:
(2 + 5) / 2 = (5 + 2) / 2 = (1 + 6) / 2 = (0 + 7) / 2 = 3.5
Note that there are of course quite a few other input values that result in an output value of 3.5. For my calculations, the 3.5 is then multiplied by 17 and the result is rounded down, giving an 8-bit color component of 59.
For reference, in case it's not obvious, the reason for the muliplication by 17 is because 15 is the largest 4-bit number, and 15 * 17 = 255, which is the largest 8-bit number. This works to double the number of bits in any number. For example, to extend a 3-bit number to 6 bits, you multiply it by (2^3) + 1, or 9. (7 * 9 = 63.) To go from 5 bits to 10 bits, multiply by (2^5) + 1, or 33. (31 * 33 = 1023.)
The thing is, in addition to ab being the same as ba, the components for the average color are calculated as (a + b) / 2, so you things like this:
(2 + 5) / 2 = (5 + 2) / 2 = (1 + 6) / 2 = (0 + 7) / 2 = 3.5
Note that there are of course quite a few other input values that result in an output value of 3.5. For my calculations, the 3.5 is then multiplied by 17 and the result is rounded down, giving an 8-bit color component of 59.
For reference, in case it's not obvious, the reason for the muliplication by 17 is because 15 is the largest 4-bit number, and 15 * 17 = 255, which is the largest 8-bit number. This works to double the number of bits in any number. For example, to extend a 3-bit number to 6 bits, you multiply it by (2^3) + 1, or 9. (7 * 9 = 63.) To go from 5 bits to 10 bits, multiply by (2^5) + 1, or 33. (31 * 33 = 1023.)