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

237
Views
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
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!