PHP Socket Programming XOR operation

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.