Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Calculator.php

function Calculator::toArbitraryBase

Converts a non-negative number to an arbitrary base using a custom alphabet.

Parameters

string $number The number to convert, positive or zero, following the Calculator conventions.:

string $alphabet The alphabet that contains every digit, validated as 2 chars minimum.:

int $base The base to convert to, validated from 2 to alphabet length.:

Return value

string The converted number in the given alphabet.

1 call to Calculator::toArbitraryBase()
Calculator::toBase in vendor/brick/math/src/Internal/Calculator.php
Converts a number to an arbitrary base.

File

vendor/brick/math/src/Internal/Calculator.php, line 409

Class

Calculator
Performs basic operations on arbitrary size integers.

Namespace

Brick\Math\Internal

Code

public final function toArbitraryBase(string $number, string $alphabet, int $base) : string {
    if ($number === '0') {
        return $alphabet[0];
    }
    $base = (string) $base;
    $result = '';
    while ($number !== '0') {
        [
            $number,
            $remainder,
        ] = $this->divQR($number, $base);
        $remainder = (int) $remainder;
        $result .= $alphabet[$remainder];
    }
    return \strrev($result);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal