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

174
Views
How can i simplify a oneliner javascript code like this

I was recently converting an obfuscated js code to python I'm not good at js when I saw this I had no clue what to do is there anyway to convert this to simple js code

return 12 === selector ? (data = data >> 4, outstring = outstring + String.fromCharCode(data)) : 18 === selector && (data = data >> 2, outstring = outstring + String.fromCharCode((65280 & data) >> 8), outstring = outstring + String.fromCharCode(255 & data)), outstring;

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

0

Here is somewhat simplified version of your code:

if (selector === 12) {
  data = data >> 4; // or data = Math.floor(data / 16), which is do right shift operation with data by 4 bits; 16 means 2 to the power of 4
  outstring += String.fromCharCode(data); // append char value of data
  return outstring;
} else if (selector === 18) {
  data = data >> 2;
  outstring = outstring + String.fromCharCode((65280 & data) >> 8); // turn higher 8 of 16 bits to a character and append
  outstring = outstring + String.fromCharCode(255 & data); // turn lower 8 of 16 bits to a character and append
}
return outstring;

If you are completely new to JS, you will probably find links String.fromCharCode() and Right shift (>>) helpful

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!