@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
18 lines (17 loc) • 555 B
JavaScript
/**
* method to separate bits from a given integer 2 positions apart
*
* @example when input is ABC, output bits are 0A0B0C
* @see https://github.com/Forceflow/libmorton/blob/234a443ca8e2c64f6385f1a9d6ee10a70d08a3fa/include/libmorton/morton2D.h#L99
* @param {number} a
* @returns {number}
*/
export function split_by_2(a) {
let x = a;
x = (x | x << 16) & 0x0000FFFF;
x = (x | x << 8) & 0x00FF00FF;
x = (x | x << 4) & 0x0F0F0F0F;
x = (x | x << 2) & 0x33333333;
x = (x | x << 1) & 0x55555555;
return x;
}