当前位置: 首页>>代码示例>>PHP>>正文


PHP bcmod函数代码示例

本文整理汇总了PHP中bcmod函数的典型用法代码示例。如果您正苦于以下问题:PHP bcmod函数的具体用法?PHP bcmod怎么用?PHP bcmod使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bcmod函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 public static function parse($unparsed)
 {
     $iban = strtolower(str_replace(' ', '', $unparsed));
     $countries = ['al' => 28, 'ad' => 24, 'at' => 20, 'az' => 28, 'bh' => 22, 'be' => 16, 'ba' => 20, 'br' => 29, 'bg' => 22, 'cr' => 21, 'hr' => 21, 'cy' => 28, 'cz' => 24, 'dk' => 18, 'do' => 28, 'ee' => 20, 'fo' => 18, 'fi' => 18, 'fr' => 27, 'ge' => 22, 'de' => 22, 'gi' => 23, 'gr' => 27, 'gl' => 18, 'gt' => 28, 'hu' => 28, 'is' => 26, 'ie' => 22, 'il' => 23, 'it' => 27, 'jo' => 30, 'kz' => 20, 'kw' => 30, 'lv' => 21, 'lb' => 28, 'li' => 21, 'lt' => 20, 'lu' => 20, 'mk' => 19, 'mt' => 31, 'mr' => 27, 'mu' => 30, 'mc' => 27, 'md' => 24, 'me' => 22, 'nl' => 18, 'no' => 15, 'pk' => 24, 'ps' => 29, 'pl' => 28, 'pt' => 25, 'qa' => 29, 'ro' => 24, 'sm' => 27, 'sa' => 24, 'rs' => 22, 'sk' => 24, 'si' => 19, 'es' => 24, 'se' => 24, 'ch' => 21, 'tn' => 24, 'tr' => 26, 'ae' => 23, 'gb' => 22, 'vg' => 24];
     $chars = ['a' => 10, 'b' => 11, 'c' => 12, 'd' => 13, 'e' => 14, 'f' => 15, 'g' => 16, 'h' => 17, 'i' => 18, 'j' => 19, 'k' => 20, 'l' => 21, 'm' => 22, 'n' => 23, 'o' => 24, 'p' => 25, 'q' => 26, 'r' => 27, 's' => 28, 't' => 29, 'u' => 30, 'v' => 31, 'w' => 32, 'x' => 33, 'y' => 34, 'z' => 35];
     if (!array_key_exists(substr($iban, 0, 2), $countries)) {
         throw new Exception('Country code ' . strtoupper(substr($iban, 0, 2)) . ' seems not valid');
     }
     if (strlen($iban) == $countries[substr($iban, 0, 2)]) {
         $movedchar = substr($iban, 4) . substr($iban, 0, 4);
         $movedchar_array = str_split($movedchar);
         $newstring = '';
         foreach ($movedchar_array as $key => $value) {
             if (!is_numeric($movedchar_array[$key])) {
                 $movedchar_array[$key] = $chars[$movedchar_array[$key]];
             }
             $newstring .= $movedchar_array[$key];
         }
         if (bcmod($newstring, '97') == 1) {
             return new static(['country' => strtoupper(substr($iban, 0, 2)), 'routing' => substr($iban, 2, 13), 'number' => substr($iban, 15), 'complete' => strtoupper($iban)]);
         } else {
             throw new Exception('IBAN ' . $unparsed . ' seems not valid!');
         }
     } else {
         throw new Exception('IBAN ' . $unparsed . ' seems not valid!');
     }
 }
开发者ID:prometherion,项目名称:iban-validator,代码行数:27,代码来源:IbanValidator.php

示例2: dec2Any

 /**
  * 10进制转其它进制
  * 
  * @access public
  * @param String $dec 十进制数据
  * @param String $toRadix 要转换的进制
  * @return String
  */
 public static function dec2Any($dec, $toRadix)
 {
     $MIN_RADIX = 2;
     $MAX_RADIX = 62;
     $num62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     if ($toRadix < $MIN_RADIX || $toRadix > $MAX_RADIX) {
         $toRadix = 2;
     }
     if ($toRadix == 10) {
         return $dec;
     }
     $buf = array();
     $charPos = 64;
     $isNegative = $dec < 0;
     if (!$isNegative) {
         $dec = -$dec;
     }
     while (bccomp($dec, -$toRadix) <= 0) {
         $buf[$charPos--] = $num62[-bcmod($dec, $toRadix)];
         $dec = bcdiv($dec, $toRadix);
     }
     $buf[$charPos] = $num62[-$dec];
     if ($isNegative) {
         $buf[--$charPos] = '-';
     }
     $_any = '';
     for ($i = $charPos; $i < 65; $i++) {
         $_any .= $buf[$i];
     }
     return $_any;
 }
开发者ID:sammychan1981,项目名称:quanpin,代码行数:39,代码来源:chips_class.php

示例3: uuid

 /**
  * 生成UUID 单机使用
  * @access public
  * @return string
  */
 public static function uuid()
 {
     list($usec, $sec) = explode(" ", microtime(false));
     $usec = (string) ($usec * 10000000);
     $timestamp = bcadd(bcadd(bcmul($sec, "10000000"), (string) $usec), "621355968000000000");
     $ticks = bcdiv($timestamp, 10000);
     $maxUint = 4294967295;
     $high = bcdiv($ticks, $maxUint) + 0;
     $low = bcmod($ticks, $maxUint) - $high;
     $highBit = pack("N*", $high);
     $lowBit = pack("N*", $low);
     $guid = str_pad(dechex(ord($highBit[2])), 2, "0", STR_PAD_LEFT) . str_pad(dechex(ord($highBit[3])), 2, "0", STR_PAD_LEFT) . str_pad(dechex(ord($lowBit[0])), 2, "0", STR_PAD_LEFT) . str_pad(dechex(ord($lowBit[1])), 2, "0", STR_PAD_LEFT) . "-" . str_pad(dechex(ord($lowBit[2])), 2, "0", STR_PAD_LEFT) . str_pad(dechex(ord($lowBit[3])), 2, "0", STR_PAD_LEFT) . "-";
     $chars = "abcdef0123456789";
     for ($i = 0; $i < 4; $i++) {
         $guid .= $chars[mt_rand(0, 15)];
     }
     $guid .= "-";
     for ($i = 0; $i < 4; $i++) {
         $guid .= $chars[mt_rand(0, 15)];
     }
     $guid .= "-";
     for ($i = 0; $i < 12; $i++) {
         $guid .= $chars[mt_rand(0, 15)];
     }
     return $guid;
 }
开发者ID:gtyd,项目名称:jira,代码行数:31,代码来源:String.php

示例4: convBase

function convBase($numberInput, $fromBaseInput, $toBaseInput)
{
    if ($fromBaseInput == $toBaseInput) {
        return $numberInput;
    }
    $fromBase = str_split($fromBaseInput, 1);
    $toBase = str_split($toBaseInput, 1);
    $number = str_split($numberInput, 1);
    $fromLen = strlen($fromBaseInput);
    $toLen = strlen($toBaseInput);
    $numberLen = strlen($numberInput);
    $retval = '';
    $base10 = '';
    if ($toBaseInput == '0123456789') {
        $retval = 0;
        for ($i = 1; $i <= $numberLen; $i++) {
            $retval = bcadd($retval, bcmul(array_search($number[$i - 1], $fromBase), bcpow($fromLen, $numberLen - $i)));
        }
        return $retval;
    }
    if ($fromBaseInput != '0123456789') {
        $base10 = convBase($numberInput, $fromBaseInput, '0123456789');
    } else {
        $base10 = $numberInput;
    }
    if ($base10 < strlen($toBaseInput)) {
        return $toBase[$base10];
    }
    while ($base10 != '0') {
        $retval = $toBase[bcmod($base10, $toLen)] . $retval;
        $base10 = bcdiv($base10, $toLen, 0);
    }
    return $retval;
}
开发者ID:Adrian0350,项目名称:zero-knowledge-keychain,代码行数:34,代码来源:functions.php

示例5: bcdechex

function bcdechex($dec, $digits = false)
{
    $hex = '';
    $positive = $dec < 0 ? false : true;
    while ($dec) {
        $hex .= dechex(abs(bcmod($dec, '16')));
        $dec = bcdiv($dec, '16', 0);
    }
    if ($digits) {
        while (strlen($hex) < $digits) {
            $hex .= '0';
        }
    }
    if ($positive) {
        return strrev($hex);
    }
    for ($i = 0; $isset($hex[$i]); $i++) {
        $hex[$i] = dechex(15 - hexdec($hex[$i]));
    }
    for ($i = 0; isset($hex[$i]) && $hex[$i] == 'f'; $i++) {
        $hex[$i] = '0';
    }
    if (isset($hex[$i])) {
        $hex[$i] = dechex(hexdec($hex[$i]) + 1);
    }
    return strrev($hex);
}
开发者ID:jasonkhanlar,项目名称:phpbitcoinscripts,代码行数:27,代码来源:gethashtarget.php

示例6: generator

 /**
  * Generate a valid prime based on which php is used. Slower than the Prime generator.
  * @return \Generator
  */
 public static function generator()
 {
     $primes = ['2'];
     $currentNumber = '2';
     (yield '2');
     while (true) {
         ++$currentNumber;
         $unitNumber = (int) substr($currentNumber, -1);
         if (($currentNumber & 1) === 0) {
             continue;
         }
         $squareRoot = bcsqrt($currentNumber);
         $foundPrimeDivisor = false;
         foreach ($primes as $prime) {
             if (bccomp($prime, $squareRoot) === 1) {
                 break;
             }
             if (bcmod($currentNumber, $prime) === '0') {
                 $foundPrimeDivisor = true;
                 break;
             }
         }
         if (!$foundPrimeDivisor) {
             $primes[] = $currentNumber;
             (yield $currentNumber);
         }
     }
 }
开发者ID:tomzx,项目名称:project-euler,代码行数:32,代码来源:BigPrime.php

示例7: validate

 /**
  * Iban validator.
  *
  * @author  petitchevalroux
  * @licence originale http://creativecommons.org/licenses/by-sa/2.0/fr/
  *
  * @link    http://dev.petitchevalroux.net/php/validation-iban-php.356.html + comments & links
  *
  * @param string $iban
  *
  * @return bool
  */
 public static function validate($iban)
 {
     /*Régles de validation par pays*/
     static $rules = array('AL' => '[0-9]{8}[0-9A-Z]{16}', 'AD' => '[0-9]{8}[0-9A-Z]{12}', 'AT' => '[0-9]{16}', 'BE' => '[0-9]{12}', 'BA' => '[0-9]{16}', 'BG' => '[A-Z]{4}[0-9]{6}[0-9A-Z]{8}', 'HR' => '[0-9]{17}', 'CY' => '[0-9]{8}[0-9A-Z]{16}', 'CZ' => '[0-9]{20}', 'DK' => '[0-9]{14}', 'EE' => '[0-9]{16}', 'FO' => '[0-9]{14}', 'FI' => '[0-9]{14}', 'FR' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'PF' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'TF' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'GP' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'MQ' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'YT' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'NC' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'RE' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'BL' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'MF' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'PM' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'WF' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'GE' => '[0-9A-Z]{2}[0-9]{16}', 'DE' => '[0-9]{18}', 'GI' => '[A-Z]{4}[0-9A-Z]{15}', 'GR' => '[0-9]{7}[0-9A-Z]{16}', 'GL' => '[0-9]{14}', 'HU' => '[0-9]{24}', 'IS' => '[0-9]{22}', 'IE' => '[0-9A-Z]{4}[0-9]{14}', 'IL' => '[0-9]{19}', 'IT' => '[A-Z][0-9]{10}[0-9A-Z]{12}', 'KZ' => '[0-9]{3}[0-9A-Z]{3}[0-9]{10}', 'KW' => '[A-Z]{4}[0-9]{22}', 'LV' => '[A-Z]{4}[0-9A-Z]{13}', 'LB' => '[0-9]{4}[0-9A-Z]{20}', 'LI' => '[0-9]{5}[0-9A-Z]{12}', 'LT' => '[0-9]{16}', 'LU' => '[0-9]{3}[0-9A-Z]{13}', 'MK' => '[0-9]{3}[0-9A-Z]{10}[0-9]{2}', 'MT' => '[A-Z]{4}[0-9]{5}[0-9A-Z]{18}', 'MR' => '[0-9]{23}', 'MU' => '[A-Z]{4}[0-9]{19}[A-Z]{3}', 'MC' => '[0-9]{10}[0-9A-Z]{11}[0-9]{2}', 'ME' => '[0-9]{18}', 'NL' => '[A-Z]{4}[0-9]{10}', 'NO' => '[0-9]{11}', 'PL' => '[0-9]{24}', 'PT' => '[0-9]{21}', 'RO' => '[A-Z]{4}[0-9A-Z]{16}', 'SM' => '[A-Z][0-9]{10}[0-9A-Z]{12}', 'SA' => '[0-9]{2}[0-9A-Z]{18}', 'RS' => '[0-9]{18}', 'SK' => '[0-9]{20}', 'SI' => '[0-9]{15}', 'ES' => '[0-9]{20}', 'SE' => '[0-9]{20}', 'CH' => '[0-9]{5}[0-9A-Z]{12}', 'TN' => '[0-9]{20}', 'TR' => '[0-9]{5}[0-9A-Z]{17}', 'AE' => '[0-9]{19}', 'GB' => '[A-Z]{4}[0-9]{14}', 'CI' => '[0-9A-Z]{2}[0-9]{22}');
     /*On vérifie la longueur minimale*/
     if (mb_strlen($iban) < 15) {
         return false;
     }
     /*On récupère le code ISO du pays*/
     $ctr = substr($iban, 0, 2);
     if (isset($rules[$ctr]) === false) {
         return false;
     }
     /*On récupère la règle de validation en fonction du pays*/
     $check = substr($iban, 4);
     /*Si la règle n'est pas bonne l'IBAN n'est pas valide*/
     if (preg_match('~^' . $rules[$ctr] . '$~', $check) !== 1) {
         return false;
     }
     /*On récupère la chaine qui permet de calculer la validation*/
     $check = $check . substr($iban, 0, 4);
     /*On remplace les caractères alpha par leurs valeurs décimales*/
     $check = str_replace(array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'), array('10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35'), $check);
     /*On effectue la vérification finale*/
     return bcmod($check, 97) === '1';
 }
开发者ID:jcomack,项目名称:IsoCodes,代码行数:38,代码来源:Iban.php

示例8: GetAuthID

function GetAuthID($i64friendID)
{
    $tmpfriendID = $i64friendID;
    $iServer = "1";
    if (extension_loaded('bcmath') == 1) {
        //decode communityid with bcmath
        if (bcmod($i64friendID, "2") == "0") {
            $iServer = "0";
        }
        $tmpfriendID = bcsub($tmpfriendID, $iServer);
        if (bccomp("76561197960265728", $tmpfriendID) == -1) {
            $tmpfriendID = bcsub($tmpfriendID, "76561197960265728");
        }
        $tmpfriendID = bcdiv($tmpfriendID, "2");
        return "STEAM_0:" . $iServer . ":" . $tmpfriendID;
    } else {
        if (extension_loaded('gmp') == 1) {
            //decode communityid with gmp
            if (gmp_mod($i64friendID, "2") == "0") {
                $iServer = "0";
            }
            $tmpfriendID = gmp_sub($tmpfriendID, $iServer);
            if (gmp_cmp("76561197960265728", $tmpfriendID) == -1) {
                $tmpfriendID = gmp_sub($tmpfriendID, "76561197960265728");
            }
            $tmpfriendID = gmp_div($tmpfriendID, "2");
            return "STEAM_0:" . $iServer . ":" . gmp_strval($tmpfriendID);
        }
    }
    return false;
}
开发者ID:GoeGaming,项目名称:bans.sevenelevenclan.org,代码行数:31,代码来源:steam.inc.php

示例9: is_prime

function is_prime($n, $k)
{
    if ($n == 2) {
        return true;
    }
    if ($n < 2 || $n % 2 == 0) {
        return false;
    }
    $d = $n - 1;
    $s = 0;
    while ($d % 2 == 0) {
        $d /= 2;
        $s++;
    }
    for ($i = 0; $i < $k; $i++) {
        $a = rand(2, $n - 1);
        $x = bcpowmod($a, $d, $n);
        if ($x == 1 || $x == $n - 1) {
            continue;
        }
        for ($j = 1; $j < $s; $j++) {
            $x = bcmod(bcmul($x, $x), $n);
            if ($x == 1) {
                return false;
            }
            if ($x == $n - 1) {
                continue 2;
            }
        }
        return false;
    }
    return true;
}
开发者ID:Gecko136,项目名称:RosettaCodeData,代码行数:33,代码来源:miller-rabin-primality-test.php

示例10: sphPack64

function sphPack64($v)
{
    assert(is_numeric($v));
    // x64 route
    if (PHP_INT_SIZE >= 8) {
        $i = (int) $v;
        return pack("NN", $i >> 32, $i & (1 << 32) - 1);
    }
    // x32 route, bcmath
    $x = "4294967296";
    if (function_exists("bcmul")) {
        $h = bcdiv($v, $x, 0);
        $l = bcmod($v, $x);
        return pack("NN", (double) $h, (double) $l);
        // conversion to float is intentional; int would lose 31st bit
    }
    // x32 route, 15 or less decimal digits
    // we can use float, because its actually double and has 52 precision bits
    if (strlen($v) <= 15) {
        $f = (double) $v;
        $h = (int) ($f / $x);
        $l = (int) ($f - $x * $h);
        return pack("NN", $h, $l);
    }
    // x32 route, 16 or more decimal digits
    // well, let me know if you *really* need this
    die("INTERNAL ERROR: packing more than 15-digit numeric on 32-bit PHP is not implemented yet (contact support)");
}
开发者ID:rafasashi,项目名称:gitorious,代码行数:28,代码来源:sphinxapi.php

示例11: decode_username

function decode_username($hash)
{
    if (!$hash) {
        return 'invalid_name';
    }
    $username = '';
    while ($hash) {
        $i = bcmod($hash, 37);
        $hash = bcdiv($hash, 37);
        if ($i == '0') {
            $username = ' ' . $username;
        } else {
            if ($i < 27) {
                if (bcmod($hash, 37) == '0') {
                    $username = chr($i + 65 - 1) . $username;
                } else {
                    $username = chr($i + 97 - 1) . $username;
                }
            } else {
                $username = chr($i + 48 - 27) . $username;
            }
        }
    }
    return $username;
}
开发者ID:tetratec,项目名称:runescape-classic-dump,代码行数:25,代码来源:server_functions.php

示例12: checkIBAN

function checkIBAN($iban)
{
    $iban = strtolower(str_replace(' ', '', $iban));
    $Countries = array('al' => 28, 'ad' => 24, 'at' => 20, 'az' => 28, 'bh' => 22, 'be' => 16, 'ba' => 20, 'br' => 29, 'bg' => 22, 'cr' => 21, 'hr' => 21, 'cy' => 28, 'cz' => 24, 'dk' => 18, 'do' => 28, 'ee' => 20, 'fo' => 18, 'fi' => 18, 'fr' => 27, 'ge' => 22, 'de' => 22, 'gi' => 23, 'gr' => 27, 'gl' => 18, 'gt' => 28, 'hu' => 28, 'is' => 26, 'ie' => 22, 'il' => 23, 'it' => 27, 'jo' => 30, 'kz' => 20, 'kw' => 30, 'lv' => 21, 'lb' => 28, 'li' => 21, 'lt' => 20, 'lu' => 20, 'mk' => 19, 'mt' => 31, 'mr' => 27, 'mu' => 30, 'mc' => 27, 'md' => 24, 'me' => 22, 'nl' => 18, 'no' => 15, 'pk' => 24, 'ps' => 29, 'pl' => 28, 'pt' => 25, 'qa' => 29, 'ro' => 24, 'sm' => 27, 'sa' => 24, 'rs' => 22, 'sk' => 24, 'si' => 19, 'es' => 24, 'se' => 24, 'ch' => 21, 'tn' => 24, 'tr' => 26, 'ae' => 23, 'gb' => 22, 'vg' => 24);
    $Chars = array('a' => 10, 'b' => 11, 'c' => 12, 'd' => 13, 'e' => 14, 'f' => 15, 'g' => 16, 'h' => 17, 'i' => 18, 'j' => 19, 'k' => 20, 'l' => 21, 'm' => 22, 'n' => 23, 'o' => 24, 'p' => 25, 'q' => 26, 'r' => 27, 's' => 28, 't' => 29, 'u' => 30, 'v' => 31, 'w' => 32, 'x' => 33, 'y' => 34, 'z' => 35);
    if (!isset($Countries[substr($iban, 0, 2)])) {
        return false;
    }
    if (strlen($iban) == $Countries[substr($iban, 0, 2)]) {
        $MovedChar = substr($iban, 4) . substr($iban, 0, 4);
        $MovedCharArray = str_split($MovedChar);
        $NewString = "";
        foreach ($MovedCharArray as $key => $value) {
            if (!is_numeric($MovedCharArray[$key])) {
                $MovedCharArray[$key] = $Chars[$MovedCharArray[$key]];
            }
            $NewString .= $MovedCharArray[$key];
        }
        if (bcmod($NewString, '97') == 1) {
            return TRUE;
        } else {
            return FALSE;
        }
    } else {
        return FALSE;
    }
}
开发者ID:bontiv,项目名称:intrateb,代码行数:27,代码来源:compta.php

示例13: ssn

 /**
  * Checks social security numbers numbers for France
  *
  * @param string $check The value to check.
  * @return boolean
  * @access public
  */
 function ssn($check)
 {
     $pattern = '/^[12]\\d{2}(0\\d|1[012])(\\d{2}|2[AB])(\\d{6}|\\d{8})$/';
     if (!preg_match($pattern, $check)) {
         return false;
     }
     // No key to check
     if (strlen($check) == 13) {
         return true;
     }
     $numberWithoutKey = substr($check, 0, -2);
     $key = substr($check, -2);
     // Corse special cases
     // source : http://xml.insee.fr/schema/nir.html
     // check : http://www.parodie.com/monetique/nir.htm
     if ($numberWithoutKey[6] == 'A') {
         $numberWithoutKey = str_replace('A', '0', $numberWithoutKey);
         $numberWithoutKey -= 1000000;
     } elseif ($numberWithoutKey[6] == 'B') {
         $numberWithoutKey = str_replace('B', '0', $numberWithoutKey);
         $numberWithoutKey -= 2000000;
     }
     // bcmod works with large numbers where % doesn't
     $expectedKey = 97 - bcmod($numberWithoutKey, 97);
     return $expectedKey == $key;
 }
开发者ID:kiang,项目名称:localized,代码行数:33,代码来源:fr_validation.php

示例14: baseConvert

 /**
  * @param $str string
  * @param $frombase int
  * @param $tobase int 
  *
  * @return string
  * 
  * Converts integers from base to another.
  */
 public static function baseConvert($str, $frombase = 10, $tobase = 36)
 {
     $str = trim($str);
     if (intval($frombase) != 10) {
         $len = strlen($str);
         $q = 0;
         for ($i = 0; $i < $len; $i++) {
             $r = base_convert($str[$i], $frombase, 10);
             $q = bcadd(bcmul($q, $frombase), $r);
         }
     } else {
         $q = $str;
     }
     if (intval($tobase) != 10) {
         $s = '';
         while (bccomp($q, '0', 0) > 0) {
             $r = intval(bcmod($q, $tobase));
             $s = base_convert($r, 10, $tobase) . $s;
             $q = bcdiv($q, $tobase, 0);
         }
     } else {
         $s = $q;
     }
     return $s;
 }
开发者ID:pvpalvk,项目名称:kyberkoulutus2,代码行数:34,代码来源:CommonUtil.php

示例15: base_convert

/**
 * Convert a large arbitrary number between arbitrary bases
 *
 * Works the same as the php version but supports large arbitrary numbers by using BCMath
 *
 * @see http://php.net/manual/en/function.base-convert.php
 * @see http://php.net/manual/en/function.base-convert.php#109660
 * @param string $number
 * @param int $frombase
 * @param int $tobase
 * @return string
 */
function base_convert($number, $frombase, $tobase)
{
    if ($frombase == $tobase) {
        return $number;
    }
    $number = trim($number);
    if ($frombase != 10) {
        $len = strlen($number);
        $fromDec = 0;
        for ($i = 0; $i < $len; $i++) {
            $v = \base_convert($number[$i], $frombase, 10);
            $fromDec = bcadd(bcmul($fromDec, $frombase, 0), $v, 0);
        }
    } else {
        $fromDec = $number;
    }
    if ($tobase != 10) {
        $result = '';
        while (bccomp($fromDec, '0', 0) > 0) {
            $v = intval(bcmod($fromDec, $tobase));
            $result = \base_convert($v, 10, $tobase) . $result;
            $fromDec = bcdiv($fromDec, $tobase, 0);
        }
    } else {
        $result = $fromDec;
    }
    return (string) $result;
}
开发者ID:phlib,项目名称:base_convert,代码行数:40,代码来源:base_convert.php


注:本文中的bcmod函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。