Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

551
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda