• How much data are you looking at sending? If you don't mind a bit of (short-term) memory overhead you can do:

    // to hex
    data.split("").map(x=>(256+x.charCodeAt()).toString(16).substr(-2)).join("")
    // from hex
    E.toString("01020304102030".match(/../g).map(x=>parseInt(x,16)))
    

    This should be reasonably fast, but it'll allocate an array so for anything over a few hundred bytes it could cause problems.

    String append is actually pretty fast & efficient in Espruino, so using your idea with a few of the hacks from above you might find this is better:

    // from hex
    for (var x of data)msg+=(256+x.charCodeAt()).toString(16).substr(-2);
    // to hex
    var l = recvData[1]*2;
    var s="";
    for (var i=0;i<l;i+=2) s+=String.fromCharCode(data.substr(i,2));
    sockData[connection]+=s;
    

    It might be that you can configure the module to output data in binary though? That might be an easier way of working.

About

Avatar for Gordon @Gordon started