So I'm making this script that needs to get the integer from the & operator of two numers in PHP. So far I have managed it to work but with small numbers (<512). When I try to do do for example:
echo 65535 $ 2048;
I get a result of 0, when it's supposed to be 2048. Any ideas why I am getting this result or how can I get the desired result?. Thank you In advance
I'm using PHP 5.5 and Ubuntu.
Asked
Active
Viewed 56 times
-4

user3875504
- 1
- 2
-
Where is `&` in `echo 65535 $ 2048;`? For my case `echo 65535 & 2048;` giving me result `2028`. – Manwal Aug 28 '14 at 04:41
-
That's obviously a typo. – Be0wulf Aug 28 '14 at 04:42
-
@Manwal, I assume you mean it gave you `2048`, yes? – paxdiablo Aug 28 '14 at 04:42
-
Sorry, there was a typo. I ment 65535 & 2048. And I also managed to solve it. Since I was getting the numbers I wanted to & from a resultset, they came in Strings instead of integer. Thanks – user3875504 Aug 28 '14 at 04:58
2 Answers
1
$
is not the and
operator, &
is.
If you try:
echo 65535 & 2048;
you should get 2048
just fine, as I just did on http://sandbox.onlinephpfunctions.com/.

paxdiablo
- 854,327
- 234
- 1,573
- 1,953
0
When you try to run this:
echo 65535 $ 2048;
You will get this error:
syntax error, unexpected '$', expecting ',' or ';'
For my case code:
echo 65535 & 2048;
Giving output 2048
Note: You have typo there should be & inplace of $. because $ is not and operator but & is.