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


PHP gmp_setbit函数代码示例

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


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

示例1: addKeyUsage

 /**
  * @param int $usageIndicator
  */
 public function addKeyUsage($usageIndicator)
 {
     if (!($usageIndicator >= 0 && $usageIndicator < 8)) {
         throw new \InvalidArgumentException();
     }
     gmp_setbit($this->bits, $usageIndicator);
 }
开发者ID:phpecc,项目名称:x509,代码行数:10,代码来源:KeyUsage.php

示例2: add

 public function add($value)
 {
     $hashes = $this->_hashes($value);
     foreach ($hashes as $hash) {
         gmp_setbit($this->_gmp, $hash);
     }
 }
开发者ID:SandeepUmredkar,项目名称:PortalSMIP,代码行数:7,代码来源:Gmp.php

示例3: BitClear

 public static function BitClear($Number, $Bit)
 {
     if (is_resource($Number) !== true) {
         $Number = gmp_init($Number);
     }
     gmp_setbit($Number, $Bit - 1, false);
     return $Number;
 }
开发者ID:davispuh,项目名称:php-utils,代码行数:8,代码来源:Utilities.php

示例4: bigint_random

 function bigint_random($n, $s)
 {
     $result = gmp_init(0);
     for ($i = 0; $i < $n; $i++) {
         if (mt_rand(0, 1)) {
             gmp_setbit($result, $i);
         }
     }
     if ($s) {
         gmp_setbit($result, $n - 1);
     }
     return $result;
 }
开发者ID:BGCX261,项目名称:ziuziu-cn-svn-to-git,代码行数:13,代码来源:bigint.php

示例5: _make_odd

 /**
  * Make the current number odd
  *
  * If the current number is odd it'll be unchanged.  If it's even, one will be added to it.
  *
  * @see self::randomPrime()
  * @access private
  */
 function _make_odd()
 {
     switch (MATH_BIGINTEGER_MODE) {
         case MATH_BIGINTEGER_MODE_GMP:
             gmp_setbit($this->value, 0);
             break;
         case MATH_BIGINTEGER_MODE_BCMATH:
             if ($this->value[strlen($this->value) - 1] % 2 == 0) {
                 $this->value = bcadd($this->value, '1');
             }
             break;
         default:
             $this->value[0] |= 1;
     }
 }
开发者ID:selectSIFISO,项目名称:.comsite,代码行数:23,代码来源:BigInteger.php

示例6: randomPrime

 /**
  * Generate a random prime number.
  *
  * If there's not a prime within the given range, false will be returned.  If more than $timeout seconds have elapsed,
  * give up and return false.
  *
  * @param optional Integer $min
  * @param optional Integer $max
  * @param optional Integer $timeout
  * @return Math_BigInteger
  * @access public
  * @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=15 HAC 4.44}.
  */
 function randomPrime($min = false, $max = false, $timeout = false)
 {
     // gmp_nextprime() requires PHP 5 >= 5.2.0 per <http://php.net/gmp-nextprime>.
     if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP && function_exists('gmp_nextprime')) {
         // we don't rely on Math_BigInteger::random()'s min / max when gmp_nextprime() is being used since this function
         // does its own checks on $max / $min when gmp_nextprime() is used.  When gmp_nextprime() is not used, however,
         // the same $max / $min checks are not performed.
         if ($min === false) {
             $min = new Math_BigInteger(0);
         }
         if ($max === false) {
             $max = new Math_BigInteger(0x7fffffff);
         }
         $compare = $max->compare($min);
         if (!$compare) {
             return $min;
         } else {
             if ($compare < 0) {
                 // if $min is bigger then $max, swap $min and $max
                 $temp = $max;
                 $max = $min;
                 $min = $temp;
             }
         }
         $x = $this->random($min, $max);
         $x->value = gmp_nextprime($x->value);
         if ($x->compare($max) <= 0) {
             return $x;
         }
         $x->value = gmp_nextprime($min->value);
         if ($x->compare($max) <= 0) {
             return $x;
         }
         return false;
     }
     $repeat1 = $repeat2 = array();
     $one = new Math_BigInteger(1);
     $two = new Math_BigInteger(2);
     $start = time();
     do {
         if ($timeout !== false && time() - $start > $timeout) {
             return false;
         }
         $x = $this->random($min, $max);
         if ($x->equals($two)) {
             return $x;
         }
         // make the number odd
         switch (MATH_BIGINTEGER_MODE) {
             case MATH_BIGINTEGER_MODE_GMP:
                 gmp_setbit($x->value, 0);
                 break;
             case MATH_BIGINTEGER_MODE_BCMATH:
                 if ($x->value[strlen($x->value) - 1] % 2 == 0) {
                     $x = $x->add($one);
                 }
                 break;
             default:
                 $x->value[0] |= 1;
         }
         // if we've seen this number twice before, assume there are no prime numbers within the given range
         if (in_array($x->value, $repeat1)) {
             if (in_array($x->value, $repeat2)) {
                 return false;
             } else {
                 $repeat2[] = $x->value;
             }
         } else {
             $repeat1[] = $x->value;
         }
     } while (!$x->isPrime());
     return $x;
 }
开发者ID:helenadeus,项目名称:s3db.map,代码行数:86,代码来源:BigInteger.php

示例7: random

 public static function random($n, $s)
 {
     switch (BigInt::support()) {
         case 'gmp':
             $result = gmp_init(0);
             for ($i = 0; $i < $n; $i++) {
                 if (mt_rand(0, 1)) {
                     gmp_setbit($result, $i);
                 }
             }
             if ($s) {
                 gmp_setbit($result, $n - 1);
             }
             return $result;
         case 'big_int':
             $result = bi_rand($n);
             if ($s) {
                 $result = bi_set_bit($result, $n - 1);
             }
             return $result;
         case 'bcmath':
             bcscale(0);
             $t = BigInt::bcpow(2, $n);
             if ($s == 1) {
                 $m = bcdiv($t, 2);
                 $t = bcsub($m, 1);
             } else {
                 $m = 0;
                 $t = bcsub($t, 1);
             }
             $l = strlen($t);
             $n = (int) ($l / 9) + 1;
             $r = '';
             while ($n) {
                 $r .= substr('000000000' . mt_rand(0, 999999999), -9);
                 --$n;
             }
             $r = substr($r, 0, $l);
             while (bccomp($r, $t) == 1) {
                 $r = substr($r, 1, $l) . mt_rand(0, 9);
             }
             return bcadd($r, $m);
         case '':
         default:
             return BigInt::_random($n, $s);
     }
 }
开发者ID:liuyu121,项目名称:myqee,代码行数:47,代码来源:bigint.class.php

示例8: findOrphanBlobs

 /**
  * Scan the blobs table for rows not registered in blob_tracking (and thus not
  * registered in the text table).
  *
  * Orphan blobs are indicative of DB corruption. They are inaccessible and
  * should probably be deleted.
  */
 function findOrphanBlobs()
 {
     if (!extension_loaded('gmp')) {
         echo "Can't find orphan blobs, need bitfield support provided by GMP.\n";
         return;
     }
     $dbw = wfGetDB(DB_MASTER);
     foreach ($this->clusters as $cluster) {
         echo "Searching for orphan blobs in {$cluster}...\n";
         $lb = wfGetLBFactory()->getExternalLB($cluster);
         try {
             $extDB = $lb->getConnection(DB_SLAVE);
         } catch (DBConnectionError $e) {
             if (strpos($e->error, 'Unknown database') !== false) {
                 echo "No database on {$cluster}\n";
             } else {
                 echo "Error on {$cluster}: " . $e->getMessage() . "\n";
             }
             continue;
         }
         $table = $extDB->getLBInfo('blobs table');
         if (is_null($table)) {
             $table = 'blobs';
         }
         if (!$extDB->tableExists($table)) {
             echo "No blobs table on cluster {$cluster}\n";
             continue;
         }
         $startId = 0;
         $batchesDone = 0;
         $actualBlobs = gmp_init(0);
         $endId = $extDB->selectField($table, 'MAX(blob_id)', false, __METHOD__);
         // Build a bitmap of actual blob rows
         while (true) {
             $res = $extDB->select($table, array('blob_id'), array('blob_id > ' . $extDB->addQuotes($startId)), __METHOD__, array('LIMIT' => $this->batchSize, 'ORDER BY' => 'blob_id'));
             if (!$res->numRows()) {
                 break;
             }
             foreach ($res as $row) {
                 gmp_setbit($actualBlobs, $row->blob_id);
             }
             $startId = $row->blob_id;
             ++$batchesDone;
             if ($batchesDone >= $this->reportingInterval) {
                 $batchesDone = 0;
                 echo "{$startId} / {$endId}\n";
             }
         }
         // Find actual blobs that weren't tracked by the previous passes
         // This is a set-theoretic difference A \ B, or in bitwise terms, A & ~B
         $orphans = gmp_and($actualBlobs, gmp_com($this->trackedBlobs[$cluster]));
         // Traverse the orphan list
         $insertBatch = array();
         $id = 0;
         $numOrphans = 0;
         while (true) {
             $id = gmp_scan1($orphans, $id);
             if ($id == -1) {
                 break;
             }
             $insertBatch[] = array('bo_cluster' => $cluster, 'bo_blob_id' => $id);
             if (count($insertBatch) > $this->batchSize) {
                 $dbw->insert('blob_orphans', $insertBatch, __METHOD__);
                 $insertBatch = array();
             }
             ++$id;
             ++$numOrphans;
         }
         if ($insertBatch) {
             $dbw->insert('blob_orphans', $insertBatch, __METHOD__);
         }
         echo "Found {$numOrphans} orphan(s) in {$cluster}\n";
     }
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:81,代码来源:trackBlobs.php

示例9: list

list($sqrt2, $sqrt2rem) = gmp_sqrtrem("7");
list($sqrt3, $sqrt3rem) = gmp_sqrtrem("1048576");
echo gmp_strval($sqrt1) . ", " . gmp_strval($sqrt1rem) . "\n";
echo gmp_strval($sqrt2) . ", " . gmp_strval($sqrt2rem) . "\n";
echo gmp_strval($sqrt3) . ", " . gmp_strval($sqrt3rem) . "\n";
// gmp_strval
$a = gmp_init("0x41682179fbf5");
printf("Decimal: %s, 36-based: %s" . PHP_EOL, gmp_strval($a), gmp_strval($a, 36));
// gmp_sub
$sub = gmp_sub("281474976710656", "4294967296");
// 2^48 - 2^32
echo gmp_strval($sub) . "\n";
// gmp_testbit
$n = gmp_init("1000000");
var_dump(gmp_testbit($n, 1));
gmp_setbit($n, 1);
var_dump(gmp_testbit($n, 1));
// gmp_xor
$xor1 = gmp_init("1101101110011101", 2);
$xor2 = gmp_init("0110011001011001", 2);
$xor3 = gmp_xor($xor1, $xor2);
echo gmp_strval($xor3, 2) . "\n";
// misc
$someBigNumber = '521384146951941511609433057270365759591953092186117381932611' . '7931051185480744623799627495673518857527248912279381830119491298336733624' . '4065664308602139494639522473719070217986094370277293176752384674818467669' . '4051320005681271452635608277857713427577896091736371787214684409012654958' . '5371050792279689258923542019956112129021960864034418159813629774771309960' . '5187072113497804995105973173281609631859502445945534690830264252230825334' . '4685035261931188171010003137835332083814206171776691473035982534904287554' . '687311595628638823537875937519577818577805321712';
$a = gmp_init($someBigNumber, 10);
var_dump(gmp_strval($a) == $someBigNumber);
var_dump(gmp_strval($a, 32));
$b = gmp_init(0xffffff, 16);
var_dump(gmp_strval($b));
$c = gmp_init($b);
var_dump(gmp_strval($c, 16));
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:mostInOne.php

示例10: gmp_init

<?php

$n = gmp_init(0);
var_dump(gmp_testbit($n, -10));
var_dump(gmp_testbit($n, 0));
var_dump(gmp_testbit($n, 1));
var_dump(gmp_testbit($n, 100));
$n = gmp_init(-1);
var_dump(gmp_testbit($n, 1));
var_dump(gmp_testbit($n, -1));
$n = gmp_init("1000000");
var_dump(gmp_testbit($n, 1));
gmp_setbit($n, 1);
var_dump(gmp_testbit($n, 1));
var_dump(gmp_strval($n));
gmp_setbit($n, 5);
var_dump(gmp_testbit($n, 5));
var_dump(gmp_strval($n));
$n = gmp_init("238462734628347239571823641234");
var_dump(gmp_testbit($n, 5));
gmp_setbit($n, 5);
var_dump(gmp_testbit($n, 5));
var_dump(gmp_strval($n));
gmp_clrbit($n, 5);
var_dump(gmp_testbit($n, 5));
var_dump(gmp_strval($n));
echo "Done\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:27,代码来源:039.php

示例11: shift_right

 /**
  * Arithmetic right shift
  * @param resource|int|string $g
  * @param int $shift number of bits to shift right
  * @return resource $g shifted right $shift bits
  */
 static function shift_right($g, $shift)
 {
     if (0 == $shift) {
         return $g;
     }
     if (0 <= gmp_sign($g)) {
         $m = gmp_div($g, gmp_pow(self::gmp_2(), $shift));
     } else {
         $g = gmp_and($g, self::gmp_0xfs());
         $m = gmp_div($g, gmp_pow(self::gmp_2(), $shift));
         $m = gmp_and($m, self::gmp_0xfs());
         for ($i = 63; $i >= 63 - $shift; $i--) {
             gmp_setbit($m, $i);
         }
         $m = gmp_neg(gmp_add(gmp_and(gmp_com($m), self::gmp_0xfs()), self::gmp_1()));
     }
     return $m;
 }
开发者ID:wikimedia,项目名称:avro,代码行数:24,代码来源:gmp.php

示例12: _make_odd

 /**
  * Make the current number odd
  *
  * If the current number is odd it'll be unchanged.  If it's even, one will be added to it.
  *
  * @see randomPrime()
  * @access private
  */
 private function _make_odd()
 {
     switch (self::$mode) {
         case Math_BigInteger::MODE_GMP:
             gmp_setbit($this->value, 0);
             break;
         case Math_BigInteger::MODE_BCMATH:
             if ($this->value[strlen($this->value) - 1] % 2 == 0) {
                 $this->value = bcadd($this->value, '1');
             }
             break;
         default:
             $this->value[0] |= 1;
     }
 }
开发者ID:tomi77,项目名称:sfPEARcaptchaPlugin,代码行数:23,代码来源:BigInteger.php

示例13: inet_ntogmp

	private static function inet_ntogmp( $addr )
	{
		// 16*8 == 128
		$gmp = gmp_init( 0 );
		for( $bits = 0; $bits < 16; $bits++ )
		{
			$byte = ord( $addr[15-$bits] );
			for( $b = 0; $b < 8; $b++ )
			{
				gmp_setbit( $gmp, $bits*8+$b, $byte & (1<<$b) );
			}
		}
//		echo inet_ntop( $addr ).' -> '.gmp_strval( $gmp, 16 )."<br />\n";
		return $gmp;
	}
开发者ID:networksoft,项目名称:seekerplus2.com,代码行数:15,代码来源:IPv6Net.class.php

示例14: gmp_init

<?php

$n = gmp_init(-1);
gmp_setbit($n, 10, -1);
var_dump(gmp_strval($n));
$n = gmp_init(5);
gmp_setbit($n, -20, 0);
var_dump(gmp_strval($n));
$n = gmp_init(5);
gmp_setbit($n, 2, 0);
var_dump(gmp_strval($n));
$n = gmp_init(5);
gmp_setbit($n, 1, 1);
var_dump(gmp_strval($n));
$n = gmp_init("100000000000");
gmp_setbit($n, 23, 1);
var_dump(gmp_strval($n));
gmp_setbit($n, 23, 0);
var_dump(gmp_strval($n));
gmp_setbit($n, 3);
var_dump(gmp_strval($n));
$b = "";
gmp_setbit($b, 23);
gmp_setbit($b);
gmp_setbit($b, 23, 1, 1);
gmp_setbit($b, array());
$a = array();
gmp_setbit($a, array());
echo "Done\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:29,代码来源:gmp_setbit.php


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