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

547
Vistas
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 Respuestas
Responde la pregunta

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