FYI, the following all accomplish the same:
if (($bytetocheck >> $bittocheck) & 1)
if ($bytetocheck & (1 << $bittocheck))
if ($bytetocheck & $bit[$bittocheck])
if (vec($bytetocheck, $bittocheck, 1))
And in the interest of eliminating redundancy,
if (($bytetocheck >> $bittocheck) & 1) { return 1; } else { return 0; }
simplifies to any of the following:
return (($bytetocheck >> $bittocheck) & 1);
return ($bytetocheck & (1 << $bittocheck)) ? 1 : 0;
return ($bytetocheck & $bit[$bittocheck]) ? 1 : 0;
return vec($bytetocheck, $bittocheck, 1);
and the following, if you're only interested in returning a boolean value:
return ($bytetocheck & (1 << $bittocheck));
return ($bytetocheck & $bit[$bittocheck]);
In reply to Re^2: Help comparing data in byte by shifting (>>) bits
by ikegami
in thread Help comparing data in byte by shifting (>>) bits
by unixhome
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |