I'm working on my Web Server using Node JS and Express.js. I need to insert hex value in a Buffer, starting from a binary string. My code is something like this:
var buffer = fs.readFileSync("myBINfile.dat");
setValue(buffer, 4);
function setValue(buffer, i) {
var value1 = parseInt(buffer[i].toString(16), 16).toString(2).toString()
value1 = "0" + value1.substring(1, value1.length);
var hex = parseInt(value1, 2).toString(16);
console.log(hex); // print a8 (correct)
buffer[i] = hex;
console.log(buffer[i]); // print 0 (why?)
}
The buffer contains a hex file. value1 is read correctly. How can fix this this problem?
Thanks
iare previusly defined and they are valid." - Can you show that? because otherwise, this code is fine, and testing it works as expected.// print a8 (correct), but this can't printa8asvalue1 = "0" + value1.substring(1, value1.length);prefixes whatever value would be in there with a 0)