low = $value & 0xFFFFFFFF; if (PHP_INT_SIZE === 8) { $this->high = ($value >> 32) & 0xFFFFFFFF; } } // Return 0 for unsigned integers and 1 for signed integers. protected function sign() { trigger_error("Not implemented", E_ERROR); } public function leftShift($count) { if ($count > 63) { $this->low = 0; $this->high = 0; return; } if ($count > 32) { $this->high = $this->low; $this->low = 0; $count -= 32; } $mask = (1 << $count) - 1; $this->high = (($this->high << $count) & 0xFFFFFFFF) | (($this->low >> (32 - $count)) & $mask); $this->low = ($this->low << $count) & 0xFFFFFFFF; $this->high &= 0xFFFFFFFF; $this->low &= 0xFFFFFFFF; return $this; } public function rightShift($count) { $sign = (($this->high & 0x80000000) >> 31) & $this->sign(); if ($count > 63) { $this->low = -$sign; $this->high = -$sign; return; } if ($count > 32) { $this->low = $this->high; $this->high = -$sign; $count -= 32; } $this->low = (($this->low >> $count) & 0xFFFFFFFF) | (($this->high << (32 - $count)) & 0xFFFFFFFF); $this->high = (($this->high >> $count) | (-$sign << $count)); $this->high &= 0xFFFFFFFF; $this->low &= 0xFFFFFFFF; return $this; } public function bitOr($var) { $this->high |= $var->high; $this->low |= $var->low; return $this; } public function bitXor($var) { $this->high ^= $var->high; $this->low ^= $var->low; return $this; } public function bitAnd($var) { $this->high &= $var->high; $this->low &= $var->low; return $this; } // Even: all zero; Odd: all one. public function oddMask() { $low = (-($this->low & 1)) & 0xFFFFFFFF; $high = $low; return UInt64::newValue($high, $low); } public function toInteger() { if (PHP_INT_SIZE === 8) { return ($this->high << 32) | $this->low; } else { return $this->low; } } public function copy() { return static::newValue($this->high, $this->low); } } class Uint64 extends GPBInteger { public static function newValue($high, $low) { $uint64 = new Uint64(0); $uint64->high = $high; $uint64->low = $low; return $uint64; } protected function sign() { return 0; } } class Int64 extends GPBInteger { public static function newValue($high, $low) { $int64 = new Int64(0); $int64->high = $high; $int64->low = $low; return $int64; } protected function sign() { return 1; } }