Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
How to split JavaScript BigInt into 5-bit chunks?

Building off of this question How to get this PRNG to generate numbers within the range? , I am making it support BigInt (big values) in JavaScript, and I think I have it right (please correct me if I did it incorrectly):

const fetch = (x, o) => {
  if (x >= o) {
    return x
  } else {
    const v = (x * x) % o
    return (x <= (o / 2n)) ? v : o - v
  }
}

const fetchLarge = (x) => fetch(x, 43214321432143214321432143214321432143214321n)

// the last number can be anything.
const buildLarge = (x, o) => fetchLarge((fetchLarge(x) + o) % BigInt(Math.pow(32, 31)) ^ 101010101010104321432143214321n)

const j = 432143213214321432143214321432143214321n; // If you don't want duplicates, either i or j should stay fixed
let i = 1n
let invalid = [];
let valid = new Set;
while (i) {
  let x = buildLarge(i, j);
  if (valid.has(x)) {
    invalid.push([i, j, x]);
  } else {
    valid.add(x);
  }
  console.log(x)
  i++;
}

console.log("invalid:", invalid);
console.log("valid:", [...valid]);
console.log("count of valid:", valid.size);

Sidenote: There should never be an invalid value.

But the main question is, given a value of x such as 40531205068036774067539981357810868028938588n, how can you divide it into an array of 5-bit values (array of integers between 0-31)?

Is it just as simple as doing x.toString(32) and then converting those letters to indices or something? Not sure if I'm doing this correctly.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To create an array with numbers between 0-31 you can just divide and collect the remainders (which you would then convert to standard number):

function createArray(n, mod=32n) {
    if (!n) return [0];
    let arr = [];
    while (n) {
        arr.push(Number(n % mod));
        n /= mod;
    }
    return arr;
}

let result = createArray(40531205068036774067539981357810868028938588n);

console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda