I have a variable, call it myNum , which contains a 32-bit value. I would like to turn it into a 4-byte string, where each byte of the string corresponds to a part of myNum .
I am trying to do something like the following (which does not work):
var myNum = someFunctionReturningAnInteger(); var str = ""; str += String.charCodeFrom((myNum >>> 24) & 0xff); str += String.charCodeFrom((myNum >>> 16) & 0xff); str += String.charCodeFrom((myNum >>> 8) & 0xff); str += String.charCodeFrom(myNum & 0xff);
For example, if myNum was 350, then str would look like 0x00 , 0x00 , 0x01 , 0x5e when I examine it in wirehark.
charCodeFrom() does just what I want, when every single byte has a value <= 0x7f. Is there a browser independent way to do what I'm trying to do?
thanks
source share