Processing, << (left shift)
用法介紹。
用法
value << n
參數
value
int:要移位的值n
int:左移的位數
說明
向左移動位。運算符左側的數字將向右移動數字指定的位數。每次向左移動會使數字翻倍,因此每次向左移動都會將原始數字乘以 2。使用左移進行快速乘法或將一組數字打包成一個更大的數字。左移僅適用於自動轉換為整數的整數或數字,例如 byte 和 char。
例子
int m = 1 << 3; // In binary: 1 to 1000
println(m); // Prints "8"
int n = 1 << 8; // In binary: 1 to 100000000
println(n); // Prints "256"
int o = 2 << 3; // In binary: 10 to 10000
println(o); // Prints "16"
int p = 13 << 1; // In binary: 1101 to 11010
println(p); // Prints "26"
// Packs four 8 bit numbers into one 32 bit number
int a = 255; // Binary: 00000000000000000000000011111111
int r = 204; // Binary: 00000000000000000000000011001100
int g = 204; // Binary: 00000000000000000000000011001100
int b = 51; // Binary: 00000000000000000000000000110011
a = a << 24; // Binary: 11111111000000000000000000000000
r = r << 16; // Binary: 00000000110011000000000000000000
g = g << 8; // Binary: 00000000000000001100110000000000
// Equivalent to "color argb = color(r, g, b, a)" but faster
color argb = a | r | g | b;
fill(argb);
rect(30, 20, 55, 55);
有關的
相關用法
- Processing <= (less than or equal to)用法及代碼示例
- Processing < (less than)用法及代碼示例
- 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大神的英文原創作品 << (left shift)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。