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

234
Visualizações
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 à 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