I have a function in JavaScript which is expecting a byte array to be passed into it from Native C++ code. For example:
function OnEvent(event, data1)
{
console.log("data1[0] = " + data1[0]);
}
I would like for it to print 0x55 or even the decimal value of it. For some reason, I am seeing the following in the console log:

How can I print the hex value of the byte or even the decimal value without printing the character?
UPDATE
I went to the link below thanks to Vinothbabu. I used the unpack function:
function unpack(str) {
var bytes = [];
$("#homePage").append("str.length = " + str.length + "<br>");
for(var i = 0, n = str.length; i < n; i++) {
var char = str.charCodeAt(i);
$("#homePage").append("char is equal to " + char + "<br>");
bytes.push(char >>> 8, char & 0xFF);
}
return bytes;
}
It prints "char is equal to 65533" and the value of "bytes" prints out "255, 253" which means it has a value of 0xFFFD.
This is not the data/payload that I was expecting. Do you know why there are 2 bytes?
I believe this will do the trick:
console.log("data1[0] = " + data1[0].toString(16));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With