Ken*_*ker 2 php porting operators
我有这个代码,我正在尝试从php移植到c/objective-c:
if ($byteIndex < count($data) ) {
$light = ( ( ($data[$byteIndex] >> $bitIndex) & 1) == 1);
}
Run Code Online (Sandbox Code Playgroud)
但我似乎无法找到>>在这里指示的任何地方.就此而言,也不是"&1".
按位运算符 - 右移和和:)
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
Run Code Online (Sandbox Code Playgroud)
问题是你在改变什么,有多少比特?它有颜色吗?
使用&和>>将十六进制转换为RGB(十进制).
$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)
Run Code Online (Sandbox Code Playgroud)
这就是:http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic =%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fbitshe.htm