@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
17 lines (16 loc) • 430 B
JavaScript
/**
* method to separate bits from a given integer 3 positions apart
* we only look at the first 10 bits
*
* @example when input is ABC, output bits are 00A00B00C
* @param {number} a
* @returns {number}
*/
export function split_by_3(a) {
let x = a;
x = (x | x << 16) & 0x30000ff;
x = (x | x << 8) & 0x0300f00f;
x = (x | x << 4) & 0x30c30c3;
x = (x | x << 2) & 0x9249249;
return x;
}