[英]Syntax/operators Java - What does this line mean?
I've found one line in Java like this : 我在Java中发现了一行,如下所示:
result |= (b & 0x1f) << shift;
I've searched about what operators do but I'm still not able to understand what it is supposed to do assuming result
, b
and shift
are integer values. 我已经搜索了运算符的作用,但我仍然无法理解它应该做什么假设
result
, b
和shift
是整数值。
Could anyone tell me what does this line is supposed to do ? 谁能告诉我这条线应该做什么?
Update - Here is the sample part of the code found here
更新 - 这是此处找到的代码的示例部分
int b, shift = 0, result = 0;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
Maybe this explanation might help you: 也许这个解释可能对你有帮助:
A.
(b & 0x1f)
: performs a logicalAND
operation betweenb
and0xf1
.A.
(b & 0x1f)
:在b
和0xf1
之间执行逻辑AND
运算。 This means: return the last 5 bits ofb
这意味着:返回
b
的最后5位B.
A << shift
: shifts to the left an amount ofshift
bits the result ofA
operation.B.
A << shift
:向左移动A
位操作结果的shift
位数。 This means: shift the last 5 bits ofb
an amount ofshift
bits to the left.这意味着:将
b
的最后5shift
位到左侧的shift
位。C.
result |= B
: assigns toresult
variable the result of perform a logicalOR
operation betweenresult
itself and the result ofB
operation.C.
result |= B
:为result
变量分配result
本身和B
操作结果之间执行逻辑OR
运算的结果。 This means: perform a logicalOR
betweenresult
and the last 5 bits ofb
shifted to the left an amount ofshift
bits, and then assign the result toresult
variable.这意味着:在
result
和b
的最后5位之间执行逻辑OR
,向左shift
一定数量的shift
位,然后将结果分配给result
变量。
Hope it be understandable. 希望这是可以理解的。
It preserves the last 5 bits of b, left shifts them some amount and ors them into result. 它保留了b的最后5位,左移了一些数量,然后将它们转换成结果。
In this case it is reversing the process described here: https://developers.google.com/maps/documentation/utilities/polylinealgorithm 在这种情况下,它正在颠倒此处描述的流程: https : //developers.google.com/maps/documentation/utilities/polylinealgorithm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.