note 71145 deleted from language.operators.bitwise by cmb
| From: | cmb@php.net | Date: | Sun, 20 Oct 2019 08:49:10 +0000 |
| Subject: | note 71145 deleted from language.operators.bitwise by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212695@lists.php.net to get a copy of this message | ||
Note Submitter: rizal dot almashoor at gmail dot com
----
The following function will perform a 32-bit left shift on a 64-bit machine:
<?php
function leftshift32($number, $steps)
{
$binary = decbin($number).str_repeat("0", $steps);
$binary = str_pad($binary, 32, "0", STR_PAD_LEFT);
$binary = substr($binary, strlen($binary) - 32);
return $binary{0} == "1" ? -(pow(2, 31) - bindec(substr($binary, 1))) : bindec($binary);
}
?>