Processing, >> (right shift)
用法介紹。
用法
value >> n
參數
value
int:要移位的值n
int:右移的位數
說明
向右移動位。運算符左側的數字將向右移動數字指定的位數。每次右移會使數字減半,因此每次右移都會將原始數字除以 2。使用右移進行快速除法或從壓縮數字中提取單個數字。右移僅適用於自動轉換為整數的整數或數字,例如字節和字符。
使用color
數據類型時,移位很有幫助。右移可以從顏色中提取紅色、綠色、藍色和 alpha 值。左移可用於快速重新組合顏色值(比color()
函數更快)。
例子
int m = 8 >> 3; // In binary: 1000 to 1
println(m); // Prints "1"
int n = 256 >> 6; // In binary: 100000000 to 100
println(n); // Prints "4"
int o = 16 >> 3; // In binary: 10000 to 10
println(o); // Prints "2"
int p = 26 >> 1; // In binary: 11010 to 1101
println(p); // Prints "13"
// Using "right shift" as a faster technique than red(), green(), and blue()
color argb = color(204, 204, 51, 255);
int a = (argb >> 24) & 0xFF;
int r = (argb >> 16) & 0xFF; // Faster way of getting red(argb)
int g = (argb >> 8) & 0xFF; // Faster way of getting green(argb)
int b = argb & 0xFF; // Faster way of getting blue(argb)
fill(r, g, b, a);
rect(30, 20, 55, 55);
有關的
相關用法
- Processing > (greater than)用法及代碼示例
- Processing >= (greater than or equal to)用法及代碼示例
- Processing FFT用法及代碼示例
- Processing SawOsc.pan()用法及代碼示例
- Processing FloatDict用法及代碼示例
- Processing FFT.stop()用法及代碼示例
- Processing join()用法及代碼示例
- Processing () (parentheses)用法及代碼示例
- Processing Pulse用法及代碼示例
- Processing PShader用法及代碼示例
- Processing PVector.set()用法及代碼示例
- Processing FloatDict.sortKeysReverse()用法及代碼示例
- Processing texture()用法及代碼示例
- Processing IntDict.add()用法及代碼示例
- Processing PShape.enableStyle()用法及代碼示例
- Processing FloatDict.sub()用法及代碼示例
- Processing String用法及代碼示例
- Processing PImage.pixels[]用法及代碼示例
- Processing vertex()用法及代碼示例
- Processing PVector.mag()用法及代碼示例
- Processing thread()用法及代碼示例
- Processing Capture.stop()用法及代碼示例
- Processing Env.play()用法及代碼示例
- Processing StringList用法及代碼示例
- Processing parseJSONArray()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 >> (right shift)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。