public function range(int $start, int $length): string
    {
        if (!$length) {
            return "0";
        }
        if ($start + $length > $this->numBits()) {
            throw new \OutOfBoundsException("Not enough bits.");
        }
        $bits = gmp_init(0);
        $idx = $start;
        $end = $start + $length;
        while (true) {
            $bit = $this->testBit($idx) ? 1 : 0;
            $bits |= $bit;
            if (++$idx >= $end) {
                break;
            }
            $bits <<= 1;
        }
        return gmp_strval($bits, 10);
    }