简体   繁体   English

语法/运算符Java - 这行是什么意思?

[英]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. 我已经搜索了运算符的作用,但我仍然无法理解它应该做什么假设resultbshift是整数值。
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 logical AND operation between b and 0xf1 . A. (b & 0x1f) :在b0xf1之间执行逻辑AND运算。 This means: return the last 5 bits of b 这意味着:返回b的最后5位

B. A << shift : shifts to the left an amount of shift bits the result of A operation. B. A << shift :向左移动A位操作结果的shift位数。 This means: shift the last 5 bits of b an amount of shift bits to the left. 这意味着:将b的最后5 shift位到左侧的shift位。

C. result |= B : assigns to result variable the result of perform a logical OR operation between result itself and the result of B operation. C. result |= B :为result变量分配result本身和B操作结果之间执行逻辑OR运算的结果。 This means: perform a logical OR between result and the last 5 bits of b shifted to the left an amount of shift bits, and then assign the result to result variable. 这意味着:在resultb的最后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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM