Ejemplo n.º 1
0
 /**
  * Decode a binary long sequence
  *
  * @param  string $data
  * @return int|float|string
  */
 protected function decodeBinLong($data)
 {
     $nbytes = strlen($data);
     if ($nbytes == 0) {
         return 0;
     }
     $long = 0;
     if ($nbytes > 7) {
         if ($this->bigIntegerAdapter === null) {
             $this->bigIntegerAdapter = BigInteger\BigInteger::getDefaultAdapter();
         }
         if (self::$isLittleEndian === true) {
             $data = strrev($data);
         }
         $long = $this->bigIntegerAdapter->binToInt($data, true);
     } else {
         for ($i = 0; $i < $nbytes; $i++) {
             $long += ord($data[$i]) * pow(256, $i);
         }
         if (0x80 <= ord($data[$nbytes - 1])) {
             $long -= pow(2, $nbytes * 8);
             // $long-= 1 << ($nbytes * 8);
         }
     }
     return $long;
 }