acondef Posted October 20, 2014 Share Posted October 20, 2014 Hello, I am trying to understand a PHP code but it use a form of grouping conditionals that I do not know and I cannot find in the documentation: for ($i = 1; $i < (1 << $len); $i++){...} if ($i & (1 << $j)){...} Any one know what is the normal form of these conditionals with && and ||? Thanks!!! Link to comment Share on other sites More sharing options...
Ingolme Posted October 20, 2014 Share Posted October 20, 2014 Those aren't conditionals, they're bitwise operators << will move bits of the left operand to the left by the amount specified on the right operand. 1 << $len is equivalent to 1 * pow(2, $len) (see pow() ) but much more efficient because computers operate in base 2 naturally. The & operator operates in binary. It compares each 0 or 1 from a binary number with the 0 or 1 from another binary number and the result has a 1 if both of them were 1, 0 if not. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now