Created
May 25, 2023 02:17
-
-
Save Rudxain/a4027545e92bb531db772838df84a5ef to your computer and use it in GitHub Desktop.
Generate a sequence of bigints with alternating bits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const alt_bit = function*() { | |
let n = 0n | |
let even = true | |
while (true) { | |
yield n | |
n <<= 1n | |
if (even) n |= 1n | |
even = !even | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment