File API - HEX Conversion - Javascript
I am trying to read a local text file with the help of the File API, and convert it to an HEX file using a similar function to 'bin2hex()' (using CharCodeAt() function), and then f
Solution 1:
Go straight into Bytes rather than via String
var file = new Blob(['hello world']); // your file
var fr = new FileReader();
fr.addEventListener('load', function () {
var u = new Uint8Array(this.result),
a = new Array(u.length),
i = u.length;
while (i--) // map to hex
a[i] = (u[i] < 16 ? '0' : '') + u[i].toString(16);
u = null; // free memory
console.log(a); // work with this
});
fr.readAsArrayBuffer(file);
Post a Comment for "File API - HEX Conversion - Javascript"