當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing & (bitwise AND)用法及代碼示例

Processing, & (bitwise AND)用法介紹。

參數

  • value1 整數、字符、字節
  • value2 整數、字符、字節

說明

比較值的二進製表示中的每個對應位。對於每次比較,兩個 1 產生 1,1 和 0 產生 0,兩個 0 產生 0。當我們查看數字的二進製表示時,這很容易看出



  11010110  // 214
& 01011100  // 92
  --------
  01010100  // 84

要查看數字的二進製表示,請使用binary()函數與println().

例子

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

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 & (bitwise AND)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。