use original count($bits) for looping

otherwise last bit(s) won't be trimed