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

215
Vistas
Javascript Converting an incoming buffer as a string to a buffer

const stringArray = ['0x00','0x3c','0xbc]

to

const array = [0x00,0x3c,0bc]

var buf = new Buffer.from(array)

How should I go about using the buffers in the string above as buffers?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You appear to have an array of strings where the strings are byte values written as hexadecimal strings. So you need to:

  • Convert each hex string to a byte; that's easily done with parseInt(str, 16) (the 16 being hexadecimal). parseInt will allow the 0x prefix. Or you could use +str or Number(str) since the prefix is there to tell them what number base to use. (More about various ways to convert strings to numbers in my answer here.)
  • Create a buffer and fill it in with the bytes.

If the array isn't massive and you can happily create a temporary array, use map and Buffer.from:

const buffer = Buffer.from(theArray.map(str => +str)));

If you want to avoid any unnecessary intermediate arrays, I'm surprised not to see any variant of Buffer.from that allows mapping, so we have to do those things separately:

const buffer = Buffer.alloc(theArray.length);
for (let index = 0; index < theArray.length; ++index) {
    buffer[index] = +theArray[index];
}
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