当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Processing | (bitwise OR)用法及代码示例


Processing, | (bitwise OR)用法介绍。

用法

  • value | value2

参数

  • value1 整数、字符、字节
  • value2 整数、字符、字节

说明

比较值的二进制表示中的每个对应位。对于每次比较,两个 1 产生 1,1 和 0 产生 1,两个 0 产生 0。当我们查看数字的二进制表示时,这很容易看出



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

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

例子

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); 

相关用法


注:本文由纯净天空筛选整理自processing.org大神的英文原创作品 | (bitwise OR)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。