note 94144 added to language.operators.bitwise
| From: | zooly at globmi dot com | Date: | Mon, 19 Oct 2009 14:52:48 +0000 |
| Subject: | note 94144 added to language.operators.bitwise | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161873@lists.php.net to get a copy of this message | ||
Here is an example for bitwise leftrotate and rightrotate.
Note that this function works only with decimal numbers - other types can be converted with pack().
<?php
function rotate ( $decimal, $bits) {
$binary = decbin($decimal);
return (
bindec(substr($binary, $bits).substr($binary, 0, $bits))
);
}
// Rotate 124 (1111100) to the left with 1 bits
echo rotate(124, 1);
// = 121 (1111001)
// Rotate 124 (1111100) to the right with 3 bits
echo rotate(124, -3);
// = 79 (1001111)
?>
----
Server IP: 69.147.83.197
Probable Submitter: 80.77.114.168
----
Manual Page -- http://www.php.net/manual/en/language.operators.bitwise.php
Edit -- https://master.php.net/note/edit/94144
Del: integrated -- https://master.php.net/note/delete/94144/integrated
Del: useless -- https://master.php.net/note/delete/94144/useless
Del: bad code -- https://master.php.net/note/delete/94144/bad+code
Del: spam -- https://master.php.net/note/delete/94144/spam
Del: non-english -- https://master.php.net/note/delete/94144/non-english
Del: in docs -- https://master.php.net/note/delete/94144/in+docs
Del: other reasons-- https://master.php.net/note/delete/94144
Reject -- https://master.php.net/note/reject/94144
Search -- https://master.php.net/manage/user-notes.php