note 84192 deleted from language.operators.bitwise by danielc

From: Date: Mon, 13 Apr 2009 16:15:38 +0000
Subject: note 84192 deleted from language.operators.bitwise by danielc
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153179@lists.php.net to get a copy of this message
Note Submitter: greenone Reason: 2 ---- 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; // split $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; } ?>

« previous php.notes (#153179) next »