In C, I'd be able to do something like this:
short number = 20693; // Create the number
unsigned char* str = malloc(3); // Create the string
memcpy(str, &number, 2); // Copy the number to the string
str[2] = 0; // 0-pad it
And then str
would contain the utf-8 representation of number
. Is it possible to do this in javascript (without the 0-padding)?
You want String.fromCharCode
...
String.fromCharCode(65); // "A"
...which is the opposite of String.charCodeAt
:
"A".charCodeAt(0); // 65
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