I have problem with AND bitwise opertion on two varialbles when I use variables such as below return correct results, for "lock" = 1, open = 0
$ACRel = "00000000000000000000010000000000";
// $STS = "11000000011100000000"; //788224 locked
$STS = "11000000001100000000"; //787200 open
echo (is_numeric($STS)&is_numeric($ACRel)); // return 1 or 0
i received $STS variable in decimal and i use decbin() function to convert:
$ACRel = "00000000000000000000010000000000";
// $sts = decbin(788224);
$sts = decbin(787200); // return 11000000001100000000
echo (is_numeric($sts)&is_numeric($ACRel));
And now i always return 1, decbin in echo return the same value but when I use var_dump i have:
$sts = "11000000001100000000";
/home/vagrant/code/project/pro/calc.php:8:string '11000000001100000000' (length=26)
$sts = decbin(788224);
/home/vagrant/code/project/pro/calc.php:12:string '11000000001100000000' (length=20)
Why length is different, strings look like same ? maybe this is answer ? but I don't know why.
Related to the problem you are describing I am seeing two problems here.
The first problem I see is, to apply the operation of an AND of bitwise over the value variables described.
But the problem here is, you are applying the AND bitwise over the boolean output of the method is_number. That means that you will always get 1 if they are correct numbers.
A solution here is, you should apply after casting the string as an int: intval.
The second problem I see here, is on the first example exposed, the content of this variable contains non numerical values:
$STS = "11000000001100000000"; //787200 open
There are some characters that are not visible, but if you check with an ASCII tool inspector you can see it: take a look here and here and copy the value of this variable, you will see that contains non numerical numbers:
11000000001100000000U+202C
So then, the method is_numeric is returning false because is not recognising this string as a numeric for that non numeric (not visible) value. And that is the reason why on the first example you get 0.