<?php

$msb = PHP_INT_SIZE * 8;
$resultado = [0 => ['qnt' => 0, 'total' => 0], 1 => ['qnt' => 0, 'total' => 0]];

for ($i = 0; $i < 20; $i++){
	$n = random_int(-100, 100);

	$isNegativo = ($n >> $msb) & 1;
	$resultado[$isNegativo]['qnt'] += 1;
	$resultado[$isNegativo]['total'] += $n;

	echo  $n . PHP_EOL;
}

echo 'Total dos positivos: ' . $resultado[0]['total'] . PHP_EOL;
echo 'Quantidade de negativos: ' . $resultado[1]['qnt'] . PHP_EOL;
