首页 > 文档 > >> (right shift) 右移
2017
07-21

>> (right shift) 右移

名称:>> (right shift)

 

例子:

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

 

描述:

Shifts bits to the right. The number to the left of the operator is shifted the number of places specified by the number to the right. Each shift to the right halves the number, therefore each left shift divides the original number by 2. Use the right shift for fast divisions or to extract an individual number from a packed number. Right shifting only works with integers or numbers which automatically convert to an integer such at byte and char.

Bit shifting is helpful when using the color data type. A right shift can extract red, green, blue, and alpha values from a color. A left shift can be used to quickly reassemble a color value (more quickly than the color() function).

向右移位位。 运算符左边的数字将由数字指定的位置数量向右移动。 每个向右移动一半的数字,因此每个左移将原始数字除以2。使用右移快速分割或从打包数中提取个别数字。 右移只适用于整数或数字,自动转换为字节和字符的整数。

使用颜色数据类型时,位移会很有用。 右移可以从颜色中提取红色,绿色,蓝色和Alpha值。 左移可用于快速重新组合颜色值(比color()函数更快)。

 

语法:

value >> n

 

参数:

value int: the value to shift                    需要转移的值
n int: the number of places to shift right        右移数

 

相关:

<< (left shift)

 



最后编辑:
作者:Hewes
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。