public function bitsPerCharacter($string)
    {
        if (is_string($string) === false) {
            throw new \InvalidArgumentException('Argument must be a string.');
        }
        $sum = 0;
        $length = strlen($string);
        foreach (array_values(array_count_values(str_split($string))) as $count) {
            $freq = $count / $length;
            $sum += $freq * log($freq, 2);
        }
        return (int) ceil(- $sum);
    }