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

238
Vistas
Converting ASCII/Base64 string to Hexadecimal in JavaScript

My input data is an array of ASCII values:

[103, 81, 70, 72, 65, 65, 111, 66, 71, 65, 77, 69, 67, 81, 73, 65, 65, 78, 67, 117]

Each element of the above array is the ASCII value of the Base64 string: "gQFHAAoBGAMECQIAANCu"

I want to convert this Base64 string to hexadecimal bytes as : 81 01 0f 00 0a 01 18 03 04 09 03 00 00 81 6e.

My approach so far:

function Decode(bytes) {
  var base64String = b2s(bytes);
  var HexValue = toHex(base64String);
  return HexValue;
}

function b2s(array) {
  return String.fromCharCode.apply(String, array);
}


function toHex(str) {
  var result = '';
  for (var i = 0; i < str.length; i++) {
    result += str.charCodeAt(i).toString(16);
  }
  return result;
}

const data = Decode([103, 81, 70, 72, 65, 65, 111, 66, 71, 65, 77, 69, 67, 81, 73, 65, 65, 78, 67, 117])
console.log(data);

The above code snippet gives me: "6751464841416f4247414d4543514941414e4375", which is a Hex string. I found some StackOverflow questions suggesting the following code snippet:

function base64ToHex(str) {
  const raw = atob(str);
  let result = '';
  for (let i = 0; i < raw.length; i++) {
    const hex = raw.charCodeAt(i).toString(16);
    result += (hex.length === 2 ? hex : '0' + hex);
  }
  return result.toUpperCase();
}

However, the atob is not available in my implementation.

Did I miss anything in my approach? Any help will be highly appreciated. 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