private function decodeBigUint($bytes) { $maxUintBytes = log(PHP_INT_MAX, 2) / 8; $byteLength = Util2::stringLength($bytes); if ($byteLength == 0) { return 0; } $numberOfLongs = ceil($byteLength / 4); $paddedLength = $numberOfLongs * 4; $paddedBytes = $this->zeroPadLeft($bytes, $paddedLength); $unpacked = array_merge(unpack("N{$numberOfLongs}", $paddedBytes)); $integer = 0; // 2^32 $twoTo32 = '4294967296'; foreach ($unpacked as $part) { // We only use gmp or bcmath if the final value is too big if ($byteLength <= $maxUintBytes) { $integer = ($integer << 32) + $part; } elseif (extension_loaded('gmp')) { $integer = gmp_strval(gmp_add(gmp_mul($integer, $twoTo32), $part)); } elseif (extension_loaded('bcmath')) { $integer = bcadd(bcmul($integer, $twoTo32), $part); } else { throw new RuntimeException('The gmp or bcmath extension must be installed to read this database.'); } } return $integer; }