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

546
Views
How to convert a hexidecimal value to Int(16) Little Endian in Javascript

For example, if I have an RGB value of 66, 135, 245 which translates to #4287f5, how would I get the int(16) Little Endian value?

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

0

Javascript allows bit-shifts, but be careful with operator precedence. The parentheses are necessary here.

function colorInteger(r,g,b){
    return (r<<16) + (g<<8) + b
}

Now colorInteger(66,135,245) gives 4360181
And '#' + colorInteger(66,135,245).toString(16) gives "#4287f5"

To get an integer from the hexadecimal value (without #), you can use parseInt('4287f5',16). You can recover the r,g,b values from that using bit operations, too.

function getRGB(hexadecimal_string){
    let intVal = parseInt(hexadecimal_string,16);
    let r = intVal >> 16;
    let g = (intVal >> 8) & 0xff 
    let b = intVal & 0xff 
    return [r,g,b]
}

I'm not sure if I understand your intention, but from the answer in another thread ( Byte order for packed images ) one single integer like ARGB is represented as [B,G,R,A] in little-endian machines.

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!