Double B Double B - 4 months ago 26
Javascript Question

Change node.js Buffer(BASE64) to jQuery

Could you help me please, I had a program which written with Node.js. It has this part:

var b = new Buffer(text, 'base64');
var s = b.toString('hex');


Do you have any idea, how could I this code change to jQuery?
I tried this, but It is not give a good values:

var text = "ACfACRv7aEcAAAAAAAD//w=="; //23,31 was the value
var b = atob(text);
console.log(b);
var s = b.toString('hex');
console.log(s);


Thank you in advance.

Answer

Convert Base64 into hex :

var base64Image = 'MjMsMzE=';

console.log(convertToHex(base64Image));

function convertToHex(base64) {

var hex = '';
for(var i=0;i<base64.length;i++) {
    hex += ''+base64.charCodeAt(i).toString(16);
}
return hex; 

}