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

200
Vistas
convert base64 to array buffer, could contain negative numbers

i have a base64 string which converted to an array buffer contains 2000 parameters of integers.

i use these functions to decode and encode the data

   const base64 = "AAABAAEAAwACAAAAAQACAAAAAAAUAAoAAAAAAAAAAAABAAAAAAABAIAMpAYsAQAAAACADNAHLAEAAAAAgAzQBywBAAAAAAAAAAAAAAAAAAAiCxQAMgAyAFgCMgAAAEYAaQAUAGQAZABkADIAAAAAAAAAAAAAAAAAAgADAAQABQAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAQABAAEAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAMABAAFAAYAAAAAAAAAAAAIADIAMgABAMIBAADIAAIAAAAKAAAAAQAAAAIAkAKg9swMsAQEAAAAAAAgA8IBAAAAAAAAAAAAAGQAigIAAAAAAAAAAJACoPbMDLAEBACU"

export const base64ToUint16ArrayBuffer = function (base64) {
  let binary_string = window.atob(base64);
  let len = binary_string.length
  let bytes = new Uint8Array(len)
  for (let i = 0; i < len; i++) {
    bytes[i] = binary_string.charCodeAt(i)
  }
  let uint16Array = new Uint16Array(bytes.buffer)
  return uint16Array
}

export const encodeArrayToBase64 = function (arrayBuffer) {
  // Converting arrayBuffer (which is a Uint16Array) to Uint8Array
  let data_8 = new Uint8Array(arrayBuffer.buffer, arrayBuffer.byteOffset, arrayBuffer.byteLength)
  // Decode array buffer to base64 string
  let arrayToBase64String = btoa(String.fromCharCode.apply(null, new Uint8Array(data_8)))
  return arrayToBase64String
}

the problem that i'm facing is that the base64 could contain negative numbers. How can i convert the base64 to get also the correct values for the negative numbers?

Thank you

about 4 years ago · Juan Pablo Isaza
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