Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript convert number to utf-8

Tags:

javascript

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)?

like image 775
MiJyn Avatar asked Dec 12 '22 14:12

MiJyn


1 Answers

You want String.fromCharCode...

String.fromCharCode(65);  // "A"

...which is the opposite of String.charCodeAt:

"A".charCodeAt(0); // 65
like image 110
meagar Avatar answered Jan 03 '23 20:01

meagar