Should use uint32_t (or at least uint16_t) for loop variables.  No need to have the common code limited to 256 channels arbitrarily.