K
K
kopytse2019-04-27 17:02:12
JavaScript
kopytse, 2019-04-27 17:02:12

What mathematical operations does this code perform?

There is JavaScript code:

function o(e) {
                    var t = arguments.length
                      , n = e & 65535
                      , r = e >> 16;
                    for (var i = 1; i < t; i++) {
                        var s = arguments[i];
                        n += s & 65535,
                        r += (s >> 16) + (n >> 16),
                        n &= 65535
                    }
                    return r << 16 | n & 65535
                }

I’ve been studying it for the second hour and I can’t understand what specific operations it performs - I don’t understand the operators |, >> and &. If you pass in it, for example, the number 100000000000000000000, it will return 1661992960.
How does this algorithm work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CHolfield, 2019-04-27
@CHolfield

they are logical and bitwise operations.
| - logical addition
& - logical multiplication
<< and >> - shift left or right by the number of bits, similar to multiplying or dividing by 2 to the specified degree
specifically how &
y = x & 65535
for x=12345
translate into binary form
11000000111001
translate 65535 there
1111111111111111
perform logical bitwise addition (look for the rules yourself)
result = 10011000000111000
translate back into decimal form
77880 something
like this)

S
Stockholm Syndrome, 2019-04-27
@StockholmSyndrome

what specific operations does it perform

bitwise

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question