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

189
Vistas
trying to make an lfsr in js

i'm trying to make an lfsr in js, on its head every thing is looking good, i'm using strings and im converting them back and forth to get the last bit, my problem is printing the number i'm trying to make a large hex number, my logic is give me a seed and a length and the function should generate a hex number in that length.

function lfsr(seed, length ){
    var arr = Array.from(seed.toString(2));
    result ="";
    for (var i = 0; i < lenght; i++) {
        let _last = parseInt(arr.pop());
        let _blast = parseInt(arr[arr.length - 1])
        let _newbit = _last ^ _blast;
        arr.splice(0 , 0 ,_newbit.toString());
        result += _newbit.toString();
    }
    return  parseInt(result, 2).toString(16); 

this is my code, i ran some tests and got a good output, but when i pring the answer i get this output:

be92231350d87800000000000

oh, and my input is this:

var ans = lfsr(6543123123798,100);

any idea how to get rid of the excess 0's and get what I need? thanks for your time.

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

0

i've changed the code to be :

function lfsr(seed, length,base){
    var arr = Array.from(seed.toString(base));
    var result ="";
    for (var i = 0; i < length ; i++) {
        let _newbit = parseInt(arr.pop(),16) ^ parseInt(arr[arr.length - 1],base);
        arr.splice(0 , 0 ,_newbit.toString(base));
        result += _newbit.toString(base); 
    }
    return  result; 
}

and it solved my problem. any one is welcome to use it.

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