名称:& (bitwise AND)
例子:
int a = 207; // In binary: 11001111 int b = 61; // In binary: 00111101 int c = a & b; // In binary: 00001101 println(c); // Prints "13", the decimal equivalent to 00001101
color argb = color(204, 204, 51, 255); // The sytax "& 0xFF" compares the binary // representation of the two values and // makes all but the last 8 bits into a 0. // "0xFF" is 00000000000000000000000011111111 int a = argb >> 24 & 0xFF; int r = argb >> 16 & 0xFF; int g = argb >> 8 & 0xFF; int b = argb & 0xFF; fill(r, g, b, a); rect(30, 20, 55, 55);
描述:
比较二进制表示的值的每个相应位。 对于每次比较有两个1得到1,1和0得到0,两个0得到0。当我们观察数字的二进制表示时,很容易看出这一点。
11010110 // 214
& 01011100 // 92
——–
01010100 // 84
要查看数字的二进制表示,请使用binary() 函数和println()。
语法:
value & value2
参数:
|
相关:
- 本文固定链接: http://iprocessing.cn/2017/07/21/bitwise-and-与/
- 转载请注明: Hewes 于 Processing编程艺术 发表
Pingback 引用通告: | (bitwise OR) 或 | Processing编程艺术