本文整理汇总了PHP中gmp_or函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_or函数的具体用法?PHP gmp_or怎么用?PHP gmp_or使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gmp_or函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setValue
public function setValue(Content $content)
{
$binaryData = $content->binaryData;
$offsetIndex = 0;
$contentLength = $this->contentLength->length;
$isNegative = (ord($binaryData[$offsetIndex]) & 0x80) != 0x0;
$number = gmp_init(ord($binaryData[$offsetIndex++]) & 0x7f, 10);
for ($i = 0; $i < $contentLength - 1; $i++) {
$number = gmp_or(gmp_mul($number, 0x100), ord($binaryData[$offsetIndex++]));
}
if ($isNegative) {
$number = gmp_sub($number, gmp_pow(2, 8 * $contentLength - 1));
}
$value = gmp_strval($number, 10);
if (is_string($value)) {
// remove gaps between hex digits
$value = preg_replace('/\\s|0x/', '', $value);
} elseif (is_numeric($value)) {
$value = dechex($value);
} else {
throw new Exception('OctetString: unrecognized input type!');
}
if (strlen($value) % 2 != 0) {
// transform values like 1F2 to 01F2
$value = '0' . $value;
}
$this->value = $value;
}
示例2: makeId32
private function makeId32($timestamp, $machine, $sequence)
{
$timestamp = gmp_mul((string) $timestamp, gmp_pow(2, 22));
$machine = gmp_mul((string) $machine, gmp_pow(2, 12));
$sequence = gmp_init((string) $sequence, 10);
$value = gmp_or(gmp_or($timestamp, $machine), $sequence);
return gmp_strval($value, 10);
}
示例3: encode
/**
* @param int $value
*
* @return string
*/
public static function encode($value)
{
$value = gmp_init($value, 10);
$octets = chr(gmp_strval(gmp_and($value, 0x7f), 10));
$rightShift = function ($number, $positions) {
return gmp_div($number, gmp_pow(2, $positions));
};
$value = $rightShift($value, 7);
while (gmp_cmp($value, 0) > 0) {
$octets .= chr(gmp_strval(gmp_or(0x80, gmp_and($value, 0x7f)), 10));
$value = $rightShift($value, 7);
}
return strrev($octets);
}
示例4: fromBinary
public static function fromBinary(&$binaryData, &$offsetIndex = 0)
{
$parsedObject = new static(0);
self::parseIdentifier($binaryData[$offsetIndex], $parsedObject->getType(), $offsetIndex++);
$contentLength = self::parseContentLength($binaryData, $offsetIndex, 1);
$isNegative = (ord($binaryData[$offsetIndex]) & 0x80) != 0x0;
$number = gmp_init(ord($binaryData[$offsetIndex++]) & 0x7f, 10);
for ($i = 0; $i < $contentLength - 1; $i++) {
$number = gmp_or(gmp_mul($number, 0x100), ord($binaryData[$offsetIndex++]));
}
if ($isNegative) {
$number = gmp_sub($number, gmp_pow(2, 8 * $contentLength - 1));
}
$parsedObject = new static(gmp_strval($number, 10));
$parsedObject->setContentLength($contentLength);
return $parsedObject;
}
示例5: add
/**
* @param $value
* @param $mask
*
* @return string
*/
public static function add($value, $mask)
{
return gmp_strval(gmp_or($value, $mask));
}
示例6: gmp_neg
// gmp_neg
$neg1 = gmp_neg("1");
echo gmp_strval($neg1) . "\n";
$neg2 = gmp_neg("-1");
echo gmp_strval($neg2) . "\n";
// gmp_nextprime
$prime1 = gmp_nextprime(10);
// next prime number greater than 10
$prime2 = gmp_nextprime(-1000);
// next prime number greater than -1000
echo gmp_strval($prime1) . "\n";
echo gmp_strval($prime2) . "\n";
// gmp_or
$or1 = gmp_or("0xfffffff2", "4");
echo gmp_strval($or1, 16) . "\n";
$or2 = gmp_or("0xfffffff2", "2");
echo gmp_strval($or2, 16) . "\n";
// gmp_perfect_square
var_dump(gmp_perfect_square("9"));
// 3 * 3, perfect square
var_dump(gmp_perfect_square("7"));
// not a perfect square
// 1234567890 * 1234567890, perfect square
var_dump(gmp_perfect_square("1524157875019052100"));
// gmp_popcount
$pop1 = gmp_init("10000101", 2);
// 3 1's
echo gmp_popcount($pop1) . "\n";
$pop2 = gmp_init("11111110", 2);
// 7 1's
echo gmp_popcount($pop2) . "\n";
示例7: bitOr
/**
* Bitwise "or" (|)
*
* @param mixed $number
* @access public
* @return self
*/
public function bitOr($number)
{
$result = gmp_or($this->getRawValue(), static::upgradeParam($number)->getRawValue());
return static::factory($result);
}
示例8: encodepoint
protected static function encodepoint($P)
{
list($x, $y) = $P;
$t = gmp_or(gmp_and($y, gmp_sub(gmp_pow(2, 256), 1)), gmp_mul(gmp_and($x, 1), gmp_pow(2, 255)));
$t = str_pad(gmp_strval($t, 16), 64, 0, STR_PAD_LEFT);
$res = strrev(pack('H*', $t));
return $res;
}
示例9: bitwiseOr
/**
* @param int|string $int
* @param int|string $otherInt
* @return string
*/
public function bitwiseOr($int, $otherInt)
{
return gmp_strval(gmp_or(gmp_init($int, 10), gmp_init($otherInt, 10)), 10);
}
示例10: bitwise_or
/**
* Logical Or
*
* @param Math_BigInteger $x
* @access public
* @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
* @return Math_BigInteger
*/
function bitwise_or($x)
{
switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP:
$temp = new Math_BigInteger();
$temp->value = gmp_or($this->value, $x->value);
return $temp;
case MATH_BIGINTEGER_MODE_BCMATH:
return new Math_BigInteger($this->toBytes() | $x->toBytes(), 256);
}
$result = new Math_BigInteger();
$x_length = count($x->value);
for ($i = 0; $i < $x_length; $i++) {
$result->value[] = $this->value[$i] | $x->value[$i];
}
return $result->_normalize();
}
示例11: var_dump
<?php
var_dump(gmp_strval(gmp_or("111111", "2222222")));
var_dump(gmp_strval(gmp_or(123123, 435234)));
var_dump(gmp_strval(gmp_or(555, "2342341123")));
var_dump(gmp_strval(gmp_or(-1, 3333)));
var_dump(gmp_strval(gmp_or(4545, -20)));
var_dump(gmp_strval(gmp_or("test", "no test")));
$n = gmp_init("987657876543456");
var_dump(gmp_strval(gmp_or($n, "34332")));
$n1 = gmp_init("987657878765436543456");
var_dump(gmp_strval(gmp_or($n, $n1)));
var_dump(gmp_or($n, $n1, 1));
var_dump(gmp_or(1));
var_dump(gmp_or(array(), 1));
var_dump(gmp_or(1, array()));
var_dump(gmp_or(array(), array()));
echo "Done\n";
示例12: decode_long_from_array
/**
* @param int[] $bytes array of ascii codes of bytes to decode
* @return string represenation of decoded long.
*/
static function decode_long_from_array($bytes)
{
$b = array_shift($bytes);
$g = gmp_init($b & 0x7f);
$shift = 7;
while (0 != ($b & 0x80)) {
$b = array_shift($bytes);
$g = gmp_or($g, self::shift_left($b & 0x7f, $shift));
$shift += 7;
}
$val = gmp_xor(self::shift_right($g, 1), gmp_neg(gmp_and($g, 1)));
return gmp_strval($val);
}
示例13: GetInfo
/**
* Get server information
*
* @throws InvalidPacketException
* @throws SocketException
*
* @return array Returns an array with information on success
*/
public function GetInfo()
{
if (!$this->Connected) {
throw new SocketException('Not connected.', SocketException::NOT_CONNECTED);
}
$this->Socket->Write(self::A2S_INFO, "Source Engine Query");
$Buffer = $this->Socket->Read();
$Type = $Buffer->GetByte();
// Old GoldSource protocol, HLTV still uses it
if ($Type === self::S2A_INFO_OLD && $this->Socket->Engine === self::GOLDSOURCE) {
/**
* If we try to read data again, and we get the result with type S2A_INFO (0x49)
* That means this server is running dproto,
* Because it sends answer for both protocols
*/
$Server['Address'] = $Buffer->GetString();
$Server['HostName'] = $Buffer->GetString();
$Server['Map'] = $Buffer->GetString();
$Server['ModDir'] = $Buffer->GetString();
$Server['ModDesc'] = $Buffer->GetString();
$Server['Players'] = $Buffer->GetByte();
$Server['MaxPlayers'] = $Buffer->GetByte();
$Server['Protocol'] = $Buffer->GetByte();
$Server['Dedicated'] = Chr($Buffer->GetByte());
$Server['Os'] = Chr($Buffer->GetByte());
$Server['Password'] = $Buffer->GetByte() === 1;
$Server['IsMod'] = $Buffer->GetByte() === 1;
if ($Server['IsMod']) {
$Mod['Url'] = $Buffer->GetString();
$Mod['Download'] = $Buffer->GetString();
$Buffer->Get(1);
// NULL byte
$Mod['Version'] = $Buffer->GetLong();
$Mod['Size'] = $Buffer->GetLong();
$Mod['ServerSide'] = $Buffer->GetByte() === 1;
$Mod['CustomDLL'] = $Buffer->GetByte() === 1;
}
$Server['Secure'] = $Buffer->GetByte() === 1;
$Server['Bots'] = $Buffer->GetByte();
if (isset($Mod)) {
$Server['Mod'] = $Mod;
}
return $Server;
}
if ($Type !== self::S2A_INFO) {
throw new InvalidPacketException('GetInfo: Packet header mismatch. (0x' . DecHex($Type) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH);
}
$Server['Protocol'] = $Buffer->GetByte();
$Server['HostName'] = $Buffer->GetString();
$Server['Map'] = $Buffer->GetString();
$Server['ModDir'] = $Buffer->GetString();
$Server['ModDesc'] = $Buffer->GetString();
$Server['AppID'] = $Buffer->GetShort();
$Server['Players'] = $Buffer->GetByte();
$Server['MaxPlayers'] = $Buffer->GetByte();
$Server['Bots'] = $Buffer->GetByte();
$Server['Dedicated'] = Chr($Buffer->GetByte());
$Server['Os'] = Chr($Buffer->GetByte());
$Server['Password'] = $Buffer->GetByte() === 1;
$Server['Secure'] = $Buffer->GetByte() === 1;
// The Ship (they violate query protocol spec by modifying the response)
if ($Server['AppID'] === 2400) {
$Server['GameMode'] = $Buffer->GetByte();
$Server['WitnessCount'] = $Buffer->GetByte();
$Server['WitnessTime'] = $Buffer->GetByte();
}
$Server['Version'] = $Buffer->GetString();
// Extra Data Flags
if ($Buffer->Remaining() > 0) {
$Server['ExtraDataFlags'] = $Flags = $Buffer->GetByte();
// The server's game port
if ($Flags & 0x80) {
$Server['GamePort'] = $Buffer->GetShort();
}
// The server's steamid
// Want to play around with this?
// You can use https://github.com/xPaw/SteamID.php
if ($Flags & 0x10) {
$SteamIDLower = $Buffer->GetUnsignedLong();
$SteamIDInstance = $Buffer->GetUnsignedLong();
// This gets shifted by 32 bits, which should be steamid instance
$SteamID = 0;
if (PHP_INT_SIZE === 4) {
if (extension_loaded('gmp')) {
$SteamIDLower = gmp_abs($SteamIDLower);
$SteamIDInstance = gmp_abs($SteamIDInstance);
$SteamID = gmp_strval(gmp_or($SteamIDLower, gmp_mul($SteamIDInstance, gmp_pow(2, 32))));
} else {
throw new \RuntimeException('Either 64-bit PHP installation or "gmp" module is required to correctly parse server\'s steamid.');
}
} else {
$SteamID = $SteamIDLower | $SteamIDInstance << 32;
//.........这里部分代码省略.........
示例14: getShared
public function getShared($S, $P)
{
if (!is_string($S) || strlen($S) !== 32) {
throw new \InvalidArgumentException();
}
// Clamp the secret key.
$n = gmp_init(bin2hex(strrev($S)), 16);
$n = gmp_and(gmp_or($n, 64), gmp_init('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8', 16));
$P0 = $this->pubkeyToPoint(strrev($P));
$P1 = $this->scalarmult($P0[0], $n);
$Q = $this->pointToPubkey($P1);
return $Q;
}
示例15: bit_or
/**
* Bitwise OR
*
* @param $value mixed anything that can be converted into an IP object
* @return IP
*/
public function bit_or($value)
{
if (!$value instanceof self) {
$value = new $this->class($value);
}
return new $this->class(gmp_or($this->ip, $value->ip));
}