How do I use % properly not to get negative result?
<?php
$x = 1103515246*12345;
echo $x." ".decbin($x)."</BR>";
$y = $x % (1 << 15);
echo $y." ".decbin($y)."</BR>";
?>
Output:
13622895711870 11010011110111000001011001111110
-27010 11111111111111111001011001111110
RESOLVED
$y = bcmod($x,(1 << 15)); Solves the issue. Thank you for quick help! It was my first question!
problem is that
$xnotintegerbutfloatand casted to negativeintwhen you use%Try use
BCMathinstead for big numbers