Syntax/operators Java - What does this line mean?
bitwise-operators, expression, java
Solution
Maybe this explanation might help you:
A. `(b & 0x1f)`: performs a logical `AND` operation between `b` and `0xf1`. This means: return the last 5 bits of `b`
B. `A << shift`: shifts to the left an amount of `shift` bits the result of `A` operation. This means: shift the last 5 bits of `b` an amount of `shift` bits to the left.
C. `result |= B`: assigns to `result` variable the result of perform a logical `OR` operation between `result` itself and the result of `B` operation. 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.
Hope it be understandable.
Problem
I've found one line in Java like this : ``` 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. 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); ```