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

187
Views
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 answers
Answer question

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 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!