Write an integer as an unsigned 16-bit value.

@param $n

@return Writer
@throws \InvalidArgumentException
163396
public function writeShort($n)
    {
        if ($n < 0 || $n > 65535) {
            throw new \InvalidArgumentException('Octet out of range 0..65535');
        }

        $this->flushBits();
        $this->out .= pack('n', $n);
        return $this;
    }
1248467
public function writeString($string)
    {
        // $maxLen = 2^16 -1 = max val of unsigned short integer.
        $maxLen = 65535;
        $len = strlen($string);

        if ($len > $maxLen) {
            $len = $maxLen;
            $string = substr($string, 0, $maxLen);
        }

        try {
            $this->getStream()->write(pack('S', $len) . $string);
        } catch (StreamException $e) {
            $this->handleStreamException($e, BinaryStreamAccessException::STRING, false);
        }
    }
706284
public void encodeUnsignedInteger(int n) throws IOException {
		if (n < 0) {
			throw new UnsupportedOperationException();
		}

		if (n < 128) {
			// write byte as is
			encode(n);
		} else {
			final int n7BitBlocks = MethodsBag.numberOf7BitBlocksToRepresent(n);

			switch (n7BitBlocks) {
			case 5:
				encode(128 | n);
				n = n >>> 7;
			case 4:
				encode(128 | n);
				n = n >>> 7;
			case 3:
				encode(128 | n);
				n = n >>> 7;
			case 2:
				encode(128 | n);
				n = n >>> 7;
			case 1:
				// 0 .. 7 (last byte)
				encode(0 | n);
			}
		}
	}
89842
public static function invertBits($n){
		$bits = \floor(\log($n, 2)) + 1;
		$mask = (1 << $bits) - 1;
		return $n ^ $mask;
	}
1054689
public function encryptInteger($n) {
		if (!is_numeric($n)) return null;
		return (PHP_INT_SIZE == 4 ? self::encrypt32($n) : self::encrypt64($n)) ^ $this->encPassword;
	}
996883
public void write8BE(final long n) {
        write((byte) (n >> 56 & 0xff));
        write((byte) (n >> 48 & 0xff));
        write((byte) (n >> 40 & 0xff));
        write((byte) (n >> 32 & 0xff));
        write((byte) (n >> 24 & 0xff));
        write((byte) (n >> 16 & 0xff));
        write((byte) (n >> 8 & 0xff));
        write((byte) (n & 0xff));
    }
765136
public function discard($n)
    {
        if ($this->length < $n) {
            throw new BufferUnderflowException();

        } elseif ($this->length === $n) {
            $this->buffer = "";
            $this->length = 0;
            return $this;

        } else {
            $this->buffer = substr($this->buffer, $n);
            $this->length -= $n;
            return $this;
        }
    }
427417
public static function bytesInt($int)
    {
        $nbytes = 1;

        if ($int > 0xFF) {
            $nbytes += 1; // 2 byte integer
        }
        if ($int > 0xFFFF) {
            $nbytes += 2; // 4 byte integer
        }
        if ($int > 0xFFFFFFFF) {
            $nbytes += 4; // 8 byte integer
        }
        if ($int < 0) {
            $nbytes += 7; // 8 byte integer (since it is signed)
        }

        return $nbytes + 1; // one „marker” byte
    }
1197532
public long readNBit(int n) throws IOException {
        if (n > 64)
            throw new IllegalArgumentException("Can not readByte more then 64 bit");

        long val = 0;

        for (int i = 0; i < n; i++) {
            val <<= 1;
            val |= read1Bit();
        }

        return val;
    }
1303926
public function format($number) {
    if ((int) $number != $number) {
      throw new \InvalidArgumentException('Number has no valid integer value.');
    }
    $sign = (int) ($number < 0);
    $number = abs($number);
    $digits = str_split($number);
    $symbols = $this->cloneNumberPatternSymbols($this->symbols[$sign]);
    $this->process($symbols[$sign], $digits);
    $this->replacePlaceholders($symbols[$sign]);
    $output = '';
    foreach ($symbols[$sign] as $symbol) {
      $output .= !is_null($symbol->replacement) ? $symbol->replacement : $symbol->symbol;
    }

    return $output;
  }
1141464
public function gexp(int $n):int{

		if($n < 0){
			$n += 255;
		}
		elseif($n >= 256){
			$n -= 255;
		}

		return Polynomial::table[$n][0];
	}
284090
public function writeBytes(string $buf, int $num = null): int
    {
        $bufSize = Binary::safeStrlen($buf);
        if (!\is_int($num) || $num > $bufSize) {
            $num = $bufSize;
        }
        // @codeCoverageIgnoreStart
        if ($num < 0) {
            throw new CannotPerformOperation('num < 0');
        }
        // @codeCoverageIgnoreEnd
        $remaining = $num;
        do {
            // @codeCoverageIgnoreStart
            if ($remaining <= 0) {
                break;
            }
            // @codeCoverageIgnoreEnd
            $written = \fwrite($this->fp, $buf, $remaining);
            if ($written === false) {
                // @codeCoverageIgnoreStart
                throw new FileAccessDenied(
                    'Could not write to the file'
                );
                // @codeCoverageIgnoreEnd
            }
            $buf = Binary::safeSubstr($buf, $written, null);
            $this->pos += $written;
            $this->stat = \fstat($this->fp);
            $remaining -= $written;
        } while ($remaining > 0);
        return $num;
    }
685760
public function writeArray($a)
    {
        $this->flushBits();
        $data = new Writer();

        foreach ($a as $v) {
            if (is_string($v)) {
                $data->write('S');
                $data->writeLongStr($v);
            } else if (is_int($v)) {
                $data->write('I');
                $data->_writeSignedLong($v);
            } else if ($v instanceof Decimal) {
                $data->write('D');
                $data->writeOctet($v->e);
                $data->_writeSignedLong($v->n);
            } else if (is_array($v)) {
                $data->write('A');
                $data->writeArray($v);
            }
        }

        $data = $data->getvalue();
        $this->writeLong(strlen($data));
        $this->write($data);
        return $this;
    }
1031491
public function withPointMovedLeft(int $n) : BigDecimal
    {
        if ($n === 0) {
            return $this;
        }

        if ($n < 0) {
            return $this->withPointMovedRight(-$n);
        }

        return new BigDecimal($this->value, $this->scale + $n);
    }
1134969
@Override
	public int writeTo(BitWriter writer) {
		if (writer == null) throw new IllegalArgumentException("null writer");
		return writer.write(bits, 64);
	}
813519
public function read($n)
    {
        $n = (int) $n;
        $raw = substr($this->bytes, $this->position, $n);
        $this->position += $n;

        return $raw;
    }
905021
public void writeNBit(long value, int n) throws IOException {
        for (int i = 0; i < n; i++) {
            write1Bit((int) (value >> (n - i - 1)) & 0x1);
        }
    }