Reputation: 12107
I have this code, I'm trying to port from php to c/objective-c:
if ($byteIndex < count($data) ) {
$light = ( ( ($data[$byteIndex] >> $bitIndex) & 1) == 1);
}
But I can't seem to find anywhere what the >> is indicating here. nor the "& 1", for that matter.
Upvotes: 2
Views: 4950
Reputation: 19380
Bitwise operators - Shift Right and And :)
http://php.net/manual/en/language.operators.bitwise.php
http://en.wikipedia.org/wiki/Bitwise_operation
$score = 2295;
echo((($score >> 2) & 1) == 1)? "1": "^1"; // 1
echo((($score >> 3) & 1) == 1)? "1": "^1"; // ^1
The question is what are you shifting and how many bits? Is it something with colors?
Using &
and >>
to convert hexadecimal to RGB (decimal).
$hex = 0xCCFF33; // my favourite :)
$r = $hex >> 16;
$g = ($hex & 0x00FF00) >> 8;
$b = $hex & 0x0000FF;
printf("rgb(%d,%d,%d)", $r, $g, $b); // rgb(204,255,51)
This is what happens: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fbitshe.htm
Upvotes: 8