note 84191 added to function.gmp-xor
| From: | greenone at osu1 dot php dot net | Date: | Wed, 02 Jul 2008 19:26:07 +0000 |
| Subject: | note 84191 added to function.gmp-xor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141083@lists.php.net to get a copy of this message | ||
here's a fast alternative to compute the xor-value of two bitstrings of an arbitrary (but same)
length.
<?php
/**
* xor-op for bitstrings of arbitrary length
* bitstrings must have same length
*
* @param string $o1
* @param string $o2
* @return string
*/
function bitxor($o1, $o2) {
$xorWidth = PHP_INT_SIZE*8;
$o1 = str_split($o1, $xorWidth);
$o2 = str_split($o2, $xorWidth);
$res = '';
$runs = count($o1);
for($i=0;$i<$runs;$i++)
$res .= decbin(bindec($o1[$i]) ^ bindec($o2[$i]));
return $res;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.179.233.161
----
Manual Page -- http://www.php.net/manual/en/function.gmp-xor.php
Edit -- https://master.php.net/note/edit/84191
Del: integrated -- https://master.php.net/note/delete/84191/integrated
Del: useless -- https://master.php.net/note/delete/84191/useless
Del: bad code -- https://master.php.net/note/delete/84191/bad+code
Del: spam -- https://master.php.net/note/delete/84191/spam
Del: non-english -- https://master.php.net/note/delete/84191/non-english
Del: in docs -- https://master.php.net/note/delete/84191/in+docs
Del: other reasons-- https://master.php.net/note/delete/84191
Reject -- https://master.php.net/note/reject/84191
Search -- https://master.php.net/manage/user-notes.php