note 24568 added to language.operators.bitwise
| From: | TheDrJoint at hotmail dot com | Date: | Wed, 21 Aug 2002 20:52:52 +0000 |
| Subject: | note 24568 added to language.operators.bitwise | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35316@lists.php.net to get a copy of this message | ||
This functions can be used for rotating the bits of an integer value(32-bit). There are operators
for that in C/C++(<<< and >>>).
// Rotates $a, $b times to the left
function RotateLeft($a, $b){
$s = $a << $b;
$c = $a >> (32 - $b);
$s = $s | $c;
return intval($s);
}
// Rotates $a, $b times to the right
function RotateRight($a, $b){
$s = $a >> $b;
$c = $a << (32 - $b);
$s = $s | $c;
return intval($s);
}
//Exapmle:
RotateRight(13, 68); //returns -805306368
RotateRight(13, 31); //returns 26
RotateRight(13, 32); //returns 13
RotateLeft(13, 68); //returns 208
RotateLeft(13, 31); //returns -2147483642
RotateLeft(13, 32); //returns 13
--
http://www.php.net/manual/en/language.operators.bitwise.php
http://master.php.net/manage/user-notes.php?action=edit+24568
http://master.php.net/manage/user-notes.php?action=delete+24568
http://master.php.net/manage/user-notes.php?action=reject+24568