Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
¿Cómo dividir JavaScript BigInt en fragmentos de 5 bits?

A partir de esta pregunta, ¿cómo hacer que este PRNG genere números dentro del rango? , lo estoy haciendo compatible con BigInt (grandes valores) en JavaScript, y creo que lo tengo bien (corríjame si lo hice incorrectamente):

 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);

Nota al margen: nunca debe haber un valor invalid .

Pero la pregunta principal es, dado un valor de x como 40531205068036774067539981357810868028938588n , ¿cómo puede dividirlo en una matriz de valores de 5 bits (matriz de números enteros entre 0 y 31)?

¿Es tan simple como hacer x.toString(32) y luego convertir esas letras en índices o algo así? No estoy seguro si estoy haciendo esto correctamente.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para crear una matriz con números entre 0 y 31, simplemente puede dividir y recopilar los restos (que luego convertiría en un número estándar):

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!