ptype of ((int32_t)0 * (uint32_t)0) is (unsigned). "i" counter was
declared unsigned to not make comparision with "unsigned char" in for loop.
This resulted in calculation in average to be implicitly casted to unsigned,
and when negative number was added to it, it turned into huge value.
Change type of "i" to signed, and just cast (unsigned char) to (int)
to fix this.
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>