Converts an ISBN-10 to an ISBN-13.

@param string $isbn The ISBN-10 to convert.

@return string The converted, unformatted ISBN-13.

@throws Exception\InvalidIsbnException If the ISBN is not a valid ISBN-10.
542682
public function convertIsbn10to13(string $isbn) : string
    {
        if ($this->cleanupBeforeValidate) {
            if (preg_match(Internal\Regexp::ASCII, $isbn) === 0) {
                throw Exception\InvalidIsbnException::forIsbn($isbn);
            }

            $isbn = preg_replace(Internal\Regexp::NON_ALNUM, '', $isbn);
        }

        $isbn = strtoupper($isbn);

        if (preg_match(Internal\Regexp::ISBN10, $isbn) === 0) {
            throw Exception\InvalidIsbnException::forIsbn($isbn);
        }

        if ($this->validateCheckDigit) {
            if (! Internal\CheckDigit::validateCheckDigit10($isbn)) {
                throw Exception\InvalidIsbnException::forIsbn($isbn);
            }
        }

        return Internal\Converter::convertIsbn10to13($isbn);
    }
767191
public function getParts() : array
    {
        if ($this->rangeInfo === null) {
            throw IsbnException::unknownGroup($this->isbn);
        }

        if ($this->rangeInfo->parts === null) {
            throw IsbnException::unknownRange($this->isbn);
        }

        return $this->rangeInfo->parts;
    }
338666
public function to13() : Isbn
    {
        if ($this->is13) {
            return $this;
        }

        return new Isbn(Internal\Converter::convertIsbn10to13($this->isbn), true);
    }
360369
protected function validateIsbn($attribute, $value, $parameters)
    {
        // Prepare value for validation
        $value = str_replace([' ', '-', '‐', '.'], '', $value);

        // Length of value
        $length = strlen($value);

        // Validate either ISBN10 or ISBN13
        if ($length == 10) {
            return $this->validateIsbn10($attribute, $value, $parameters);
        } elseif ($length == 13) {
            return $this->validateIsbn13($attribute, $value, $parameters);
        }

        return false;
    }
91407
public static function checkIsbn10Number($isbn)
    {
        $isbn = trim($isbn);
        if (mb_strlen($isbn) !== 10 || preg_match('/0{10}/', $isbn)) {
            throw new MsgException("ISBN10 형식에 맞지 않습니다.");
        }

        $total = 0;
        for ($i = 0; $i < 9; $i++) {
            $digit = intval(substr($isbn, $i, 1));
            $total += ((10 - $i) * $digit);
        }

        $check_sum = (11 - ($total % 11)) % 11;
        if ($check_sum === 10) {
            $check_sum = 'X';
        }

        if ($check_sum != substr($isbn, 9)) {
            throw new MsgException("ISBN10 형식에 맞지 않습니다.");
        }
    }
1164413
public static function getISBN13CheckDigit($isbn)
    {
        $sum = 0;
        $weight = 1;
        for ($x = 0; $x < strlen($isbn); $x++) {
            $sum += intval(substr($isbn, $x, 1)) * $weight;
            $weight = $weight == 1 ? 3 : 1;
        }
        $retval = 10 - ($sum % 10);
        return $retval == 10 ? 0 : $retval;
    }
266740
public static function of(string $isbn) : Isbn
    {
        if (preg_match(Internal\Regexp::ASCII, $isbn) === 0) {
            throw Exception\InvalidIsbnException::forIsbn($isbn);
        }

        $isbn = preg_replace(Internal\Regexp::NON_ALNUM, '', $isbn);

        if (preg_match(Internal\Regexp::ISBN13, $isbn) === 1) {
            if (! Internal\CheckDigit::validateCheckDigit13($isbn)) {
                throw Exception\InvalidIsbnException::forIsbn($isbn);
            }

            return new Isbn($isbn, true);
        }

        $isbn = strtoupper($isbn);

        if (preg_match(Internal\Regexp::ISBN10, $isbn) === 1) {
            if (! Internal\CheckDigit::validateCheckDigit10($isbn)) {
                throw Exception\InvalidIsbnException::forIsbn($isbn);
            }

            return new Isbn($isbn, false);
        }

        throw Exception\InvalidIsbnException::forIsbn($isbn);
    }
268084
private boolean checkChecksumISBN10(final String isbn) {
    int sum = 0;
    for (int i = 0; i < isbn.length() - 1; i++) {
      sum += (isbn.charAt(i) - '0') * (i + 1);
    }
    final char checkSum = isbn.charAt(9);
    return sum % 11 == (checkSum == 'X' ? 10 : checkSum - '0');
  }
696411
public static function dec2big(string $number): string
    {
    	static::checkExtensionOrFail();

        $alphabet = static::NUMBERS;
        $number = trim((string)$number);

        if (strlen($number) == 0) {
            throw new Exception('Got empty number for dec2big, can not proceed');
        }

        $mod = (string)count($alphabet);
        $s = '';

        do {
            $x = bcdiv($number, $mod, 0);
            $left = bcmod($number, $mod);
            $char = $alphabet[$left];
            $s = $char . $s;

            $number = $x;
        } while ($x != '0');

        return $s;
    }
907705
public function fixIsbnNumber( $isbn_number ) {

		// Regex to split a string only by the last whitespace character
		@list( $isbn_number, $addon ) = preg_split( '/\s+(?=\S*+$)/', trim( $isbn_number ) ); // @codingStandardsIgnoreLine

		$isbn_number = ( new \Isbn\Isbn() )->hyphens->fixHyphens( $isbn_number );

		if ( $addon ) {
			$isbn_number .= " $addon";
		}

		return $isbn_number;
	}
560311
public static String isbn() {
        StringBuffer stringBuffer = new StringBuffer("09");
        stringBuffer.append(String.format("%06d", JDefaultNumber.randomIntBetweenTwoNumbers(0, 49999)));
        stringBuffer.append(String.format("%02d", JDefaultNumber.randomIntBetweenTwoNumbers(0, 99)));
        String numberString = stringBuffer.toString();


        int number = Integer.parseInt(numberString);
        int sum = 0;
        for (int i = 2; i <= 10; i++) {
            int digit = number % 10;                // rightmost digit
            sum = sum + i * digit;
            number = number / 10;
        }

        // Determine check digit, use X for 10
        String checkDigit = null;
        if (sum % 11 == 1) {
            checkDigit = "X";
        } else if (sum % 11 == 0) {
            checkDigit = "0";
        } else {
            checkDigit = (11 - (sum % 11)) + "";
        }

        //  System.out.println("The full ISBN number is " + numberString+checkDigit);
        String returnString = stringBuffer.toString();
        returnString = returnString.substring(0, 1) + "-" + returnString.substring(1, 7) + "-" + returnString.substring(7, 9) + "-" + checkDigit;

        return returnString;
    }
1250797
private function createISBNText() {
        $isbn = '';
        if (!empty($this->text)) {
            // We try to create the ISBN Text... the hyphen really depends the ISBN agency.
            // We just put one before the checksum and one after the GS1 if present.
            $c = strlen($this->text);
            if ($c === 12 || $c === 13) {
                // If we have 13 characters now, just transform it temporarily to find the checksum...
                // Further in the code we take care of that anyway.
                $lastCharacter = '';
                if ($c === 13) {
                    $lastCharacter = $this->text[12];
                    $this->text = substr($this->text, 0, 12);
                }

                $checksum = $this->processChecksum();
                $isbn = 'ISBN ' . substr($this->text, 0, 3) . '-' . substr($this->text, 3, 9) . '-' . $checksum;

                // Put the last character back
                if ($c === 13) {
                    $this->text .= $lastCharacter;
                }
            } elseif ($c === 9 || $c === 10) {
                $checksum = 0;
                for ($i = 10; $i >= 2; $i--) {
                    $checksum += $this->text[10 - $i] * $i;
                }

                $checksum = 11 - $checksum % 11;
                if ($checksum === 10) {
                    $checksum = 'X'; // Changing type
                }

                $isbn = 'ISBN ' . substr($this->text, 0, 9) . '-' . $checksum;
            }
        }

        return $isbn;
    }
925972
public static function format(string $isbn) : string
    {
        $rangeInfo = self::getRangeInfo($isbn);

        if ($rangeInfo !== null && $rangeInfo->parts !== null) {
            return implode('-', $rangeInfo->parts);
        }

        return $isbn;
    }
1044958
public function buildLenEncodedBinary($s)
    {
        if ($s === null) {
            return "\251";
        }

        $l = mb_orig_strlen($s);

        if ($l <= 250) {
            return chr($l) . $s;
        }

        if ($l <= 0xFFFF) {
            return "\252" . Binary::int2bytes(2, true) . $s;
        }

        if ($l <= 0xFFFFFF) {
            return "\254" . Binary::int2bytes(3, true) . $s;
        }

        return Binary::int2bytes(8, $l, true) . $s;
    }
1372561
public function getIsbn10() : ?string 
    {
        if ( ! $this->hasIsbn10()) {
            $this->setIsbn10($this->getDefaultIsbn10());
        }
        return $this->isbn10;
    }
621965
public static function fromIsbn13($isbn, $onError = null)
    {
        // Sanitize
        $isbn = preg_replace('/[^0-9]/', '', $isbn);

        // Validate
        if (strlen($isbn) != 13) {
            return $onError;
        }

        return $isbn;
    }
732942
public static function getNumberBaseFromString($value)
    {
        if (substr($value, 0, 1) == 'b')
            return self::BINARY;

        if (substr($value, 0, 1) == 'o')
            return self::OCTAL;

        if (substr($value, 0, 2) == '0x')
            return self::HEXADECIMAL;

        if (is_numeric($value))
            return self::DECIMAL;

        throw new \Exception ("not a number ".$value);
    }