Is it possible to easily convert the string
"4 | 2"
into a standard bitwise comparison so it returns 6.
So that I could accomplish something like this
$var1 = "4 | 2";
if(evalAsBitwise($var1) & 2) {
return true;
} else {
return false;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you split your string with space as the delimiter, you will get three parts: the first number, the operator, and the second number. In your function, you can use switch to determine what operator to use.
Something like
You would also need to test for ~. But it gets more complicated if you need it do more complicated expressions like (a & b ^ (c ^ d)).