Decoder Base64 to Hex

Hello everyone,

I am currently writing a decoder for a sensor. The standart decoder from the producer uses Hex to decode.

Since my Data comes in Base64 I need a function to convert to Hex.

Sadly I coundn’t find a solution for a function. I used

function byte2HexString(bytes) {
var retHexString = “”;
bytes.forEach(function (el) {
retHexString = retHexString.concat((“0” + (Number(el).toString(16))).slice(-2).toUpperCase());
return retHexString;

But I get the error that “for Each” is not a function

I also tryed

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

Where I get the Error “atob is not defined”.

I am an Beginner for programing. If I unterstand it corretly it has to do with JavaScript “Otto”. Does anyone else had the same problem and found a solution?

Kind regards


What version are you using?