Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
Conversión de cadena ASCII/Base64 a hexadecimal en JavaScript

Mis datos de entrada son una matriz de valores ASCII:

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

Cada elemento de la matriz anterior es el valor ASCII de la cadena Base64: "gQFHAAoBGAMECQIAANCu"

Quiero convertir esta cadena Base64 a bytes hexadecimales como: 81 01 0f 00 0a 01 18 03 04 09 03 00 00 81 6e .

Mi enfoque hasta ahora:

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

El fragmento de código anterior me da: "6751464841416f4247414d4543514941414e4375" , que es una cadena hexadecimal. Encontré algunas preguntas de StackOverflow que sugerían el siguiente fragmento de código:

 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(); }

Sin embargo, atob no está disponible en mi implementación.

¿Me perdí algo en mi enfoque? Cualquier ayuda será muy apreciada. Gracias.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!