Pedro Dusso
Pedro Dusso

Reputation: 2140

Storing two ints in a long

This question is a extension to this. Is it possible to store two integers in a long in JavaScript?

long l = (((long)x) << 32) | (y & 0xffffffffL);
int x = (int)(l >> 32);
int y = (int)l;

Upvotes: 1

Views: 166

Answers (1)

Beri
Beri

Reputation: 11620

It's JavaScript, not java. Here you got only floating point numbers. I don't see any point in such operation, but you could return a tuple, or make a string out of them with a separator. But keeping them inside one number...

But in JS you have also shifting operator, so you could try this one:D

Upvotes: 1

Related Questions