Fractional and integer charges from Levinson's theorem