Hi,
Does anyone have a function that converts an ascii string to decimal (string)?
So if pass “ABCD1” into the function the output would be “65” “66” “67” “68” “49”
Hi,
Does anyone have a function that converts an ascii string to decimal (string)?
So if pass “ABCD1” into the function the output would be “65” “66” “67” “68” “49”
Use a function node.
const stringToConvert = msg.payload;
msg.payload = getCharCodes(stringToConvert).join(" ");
return msg;
function getCharCodes(s){
let charCodeArr = [];
for(let i = 0; i < s.length; i++){
let code = s.charCodeAt(i);
charCodeArr.push(code);
}
return charCodeArr;
}
Proof...
Do you really want a string of quotes and numbers? or did you want an array of strings???
Legend this is exactly what I needed!!! Much appreciated!
or take advantage of nodejs Buffer
msg.payload = Buffer.from(msg.payload, 'ascii').join(" ")
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.