首页 > 文档 > & (bitwise AND) 与
2017
07-21

& (bitwise AND) 与

名称:& (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

 

参数:

value1 int, char, byte
value2 int, char, byte

 

相关:

| (bitwise OR)
binary()

 



最后编辑:
作者:Hewes
这个作者貌似有点懒,什么都没有留下。

& (bitwise AND) 与》有 1 条评论

  1. Pingback 引用通告: | (bitwise OR) 或 | Processing编程艺术

留下一个回复

你的email不会被公开。