note 17895 added to function.isset
| From: | jes303 at xs4all dot nl | Date: | Tue, 01 Jan 2002 17:05:12 +0000 |
| Subject: | note 17895 added to function.isset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-24033@lists.php.net to get a copy of this message | ||
I couldn't find a function which checks if a bit is set in a
bit pattern / integer value. So I wrote one myself.
function isbitset($myint, $mybit, $mybitsize) {
$mystring = substr(str_repeat("0", $mybitsize) . decbin($myint), -$mybitsize, $mybitsize);
$mysubstr = substr($mystring, $mybit, 1);
return ($mysubstr || !$mysubstr == 0) ? true : false;
}
The function will return true if the bit in question is set,
or false if it it isn't set.
$myint
------
The integer value that you want to check its bits.
$mybit
------
The bit number you want to check whether set or not,
where $mybit = 0 means you are checking the msb, in
other words the first bit from the left.
$mybitsize
----------
The number of bits which the value $myint could consist
of, when all bits would be set. For example, to test bit
number 0 (msb) of a bitsize of 8 would result true, while
the same test of bit number 0 of a bitsize of 16 would result
false if $myint was 255.
See for yourself whether useful and without bugs.
I don't know if there's a better approach than this,
just let me know.
Greets, Jeroen.
--
http://www.php.net/manual/en/function.isset.php
http://master.php.net/manage/user-notes.php?action=edit+17895
http://master.php.net/manage/user-notes.php?action=delete+17895
http://master.php.net/manage/user-notes.php?action=reject+17895