assigning a constant by prefixing 0x to a variable stores it as hex value, not as a string. $a=0xa1; //this 161 in decimal but if I already have a value somewhere, then how do I assign it same as above? $some_value = "a10ce2"; $a= substr($some_value, 0, 2); //this is not same as $a=0xa1; I've to use it for XOR checksum, I already have values in a text file, so I'll read a line and use XOR to validate. $a=0x87;$b=0xa0;$c=0x03;$d=0x00;$e=0x0c;$f=0x28; echo $a ^ $b ^ $c ^ $d ^ $e ^ $f; //perfectly returns 0; but this is a constant assigned to a variable, when we already have values: $values = "87a003000c28"; $a=substr($values, 0, 2); $b=substr($values, 2, 2); $c=substr($values, 4, 2); $d=substr($values, 6, 2); $e=substr($values, 8, 2); $f=substr($values, 10, 2); echo $a^$b^$c^$d^$e^$f; //does not return 0;
$values = "87a003000c28"; $stra=substr($values, 0, 2); $strb=substr($values, 2, 2); ... eval ("\$a = 0x$stra;\$b = 0x$strb;"); echo $a^$b^$c^$d^$e^$f; PHP: ... and so on. Does that work?