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)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。