Skip to content

Instantly share code, notes, and snippets.

@Rudxain
Created May 25, 2023 02:17
Show Gist options
  • Save Rudxain/a4027545e92bb531db772838df84a5ef to your computer and use it in GitHub Desktop.
Save Rudxain/a4027545e92bb531db772838df84a5ef to your computer and use it in GitHub Desktop.
Generate a sequence of bigints with alternating bits
'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