PHP socket Programming XOR or arithmetic help
, in the socket programming, using the XOR operation, part of the code is attached. But now encountered such a problem, the picture is a different or the result of the operation, the calculation of something echo out is some smiley face, if you look closely, the smiley face represents 1, the blank position is 0. XOR is the value of its own calculation, Revc_xor is the received XOR value (considered correct). The length is 8 bits.
Ask the great God to tell the correct XOR code or how to fix the problem.
$check = Str_split ($verify _data, 2); Converting 16 of binary data into two arrays
for ($j = 0; $j < count ($check); $j + +) {
$data = Str_pad (Base_convert ($check [$j],16,2), 8,0,str_pad_left);
$xor = $xor ^ $data;
$xor = Str_pad ($xor, 8,0,str_pad_left);
}
echo "XOR:". $xor. "\ r \ n";
echo "Revc_xor:". $REVC _xor. "\r\n\r\n";
Where $verify_data is a string of 16 binary numbers, from the Bin2Hex (Socket_read ($msgsock, 8192,php_binary_read)) passed over.
Thank you
------to solve the idea----------------------
$s = ' 81000000003e900000000000000010001031323334353632 ';
$a = unpack (' c* ', pack (' h* ', $s));
$x = 29;
foreach ($a as $v) $x ^= $v;
printf ('%08b ', $x);
00000111