首页 > 文档 > | (bitwise OR) 或
2017
07-21

| (bitwise OR) 或

名称:| (bitwise OR)

 

例子:

int a = 205;   // In binary: 11001101
int b = 45;    // In binary: 00101101
int c = a | b; // In binary: 11101101
println(c);    // Prints "237", the decimal equivalent to 11101101

int a = 255 << 24; // Binary: 11111111000000000000000000000000
int r = 204 << 16; // Binary: 00000000110011000000000000000000
int g = 204 << 8;  // Binary  00000000000000001100110000000000
int b = 51;        // Binary: 00000000000000000000000000110011
// OR the values together:    11111111110011001100110000110011 
color argb = a | r | g | b; 
fill(argb); 
rect(30, 20, 55, 55); 

 

描述:

Compares each corresponding bit in the binary representation of the values. For each comparison two 1’s yield 1, 1 and 0 yield 1, and two 0’s yield 0. This is easy to see when we look at the binary representation of numbers
比较二进制表示的值的每个相应位。 每次比较可发现,两个1得到1,1和0得到1,两个0得到0.当我们观察数字的二进制表示时,很容易看出这一点。

  11010110  // 214
| 01011100  // 92
  --------
  11011110  // 222

To see the binary representation of a number, use the binary() function with println().

要查看数字的二进制表示,请使用binary() 函数和println()。

 

语法:

value | value2

 

参数:

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

 

相关:

& (bitwise AND)
binary()

 



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

| (bitwise OR) 或》有 1 条评论

  1. Pingback 引用通告: & (bitwise AND) 与 | Processing编程艺术

留下一个回复

你的email不会被公开。