-2

I've been trying to get a code together that would deduce what alternatives have been check in a multi-choice exam, but using sums of powers of two.

I found the following code online, but I'm not sure HOW it works, especially the operator <<. I could not find this on Google or PHPDoc.

Thank you.

$aSums = array();
for ($iCount = 0; $iCount < 32; $iCount++)
{
    $iMask = 1 << $iCount;

    if (($iNumber & $iMask) != 0)
    $aSums[] = $iMask;
}
return $aSums;
henriquesirot
  • 115
  • 2
  • 14

2 Answers2

0

It's a bitwise shift left, that is, multiply by 2^N.

dkellner
  • 8,726
  • 2
  • 49
  • 47
0

It's a bitwise operator Shift left. From PHP documentation:

Shift the bits of $a $b steps to the left (each step means "multiply by two")

amatellanes
  • 3,645
  • 2
  • 17
  • 19