You are viewing a single comment's thread. Return to all comments →
My Typescript solution:
function flippingBits(n: number): number { let splitBinary = n.toString(2).split(""); let base2 = new Uint32Array(32); const sbLength = splitBinary.length; for (let i = 0; i < 32; i++) { const sbIndexInverse = 32 - i; if (sbIndexInverse <= sbLength) { base2[i] = Number(splitBinary[sbLength - sbIndexInverse]) } base2[i] = base2[i] === 0 ? 1 : 0; } return parseInt(base2.join(""), 2); }
Seems like cookies are disabled on this browser, please enable them to open this website
Flipping bits
You are viewing a single comment's thread. Return to all comments →
My Typescript solution: