/**
  * @dataProvider getBnNumBytesNumbers
  */
 public function testNumBytes(MathAdapterInterface $adapter, $number, $expected)
 {
     $size = NumberSize::bnNumBytes($adapter, $adapter->hexDec($number));
     $this->assertEquals($expected, $size);
 }
Example #2
0
 /**
  * @param int|string $integer
  * @param bool $fNegative
  * @return int|string
  */
 public function parseCompact($integer, $fNegative)
 {
     if (!is_bool($fNegative)) {
         throw new \InvalidArgumentException('CompactInteger::read() - flag must be boolean!');
     }
     $size = (int) NumberSize::bnNumBytes($this, $integer);
     if ($this->cmp($size, 3) <= 0) {
         $compact = $this->leftShift($this->getLow64($integer), $this->mul(8, $this->sub(3, $size)));
     } else {
         $compact = $this->rightShift($integer, $this->mul(8, $this->sub($size, 3)));
         $compact = $this->getLow64($compact);
     }
     if ($this->cmp($this->bitwiseAnd($compact, $this->hexDec('00800000')), 0) > 0) {
         $compact = $this->rightShift($compact, 8);
         $size++;
     }
     $compact = $this->bitwiseOr($compact, $this->leftShift($size, 24));
     if ($fNegative && $this->cmp($this->bitwiseAnd($compact, $this->hexDec('007fffff')), 0) > 0) {
         /// ?
         $compact = $this->bitwiseOr($compact, $this->hexDec('00800000'));
     }
     return $compact;
 }