/** * Returns the number of bits used to store this number. Non-singicant upper bits are not counted. * * @param MathAdapterInterface $adapter * @param int|string $x * @return number * * @link https://www.openssl.org/docs/crypto/BN_num_bytes.html */ public static function bnNumBits(MathAdapterInterface $adapter, $x) { if ($adapter->cmp($x, '0') == 0) { return 0; } $log2 = 0; while ($x = $adapter->rightShift($x, 1)) { $log2++; } return $log2 + 1; }
/** * @param $integer * @param $bitSize * @return bool */ public function isNegative($integer, $bitSize) { return $this->math->cmp($this->math->rightShift($integer, $this->fixSize($bitSize)), '1') == 0; }