4

在 C 中,我可以做这样的事情:

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

然后str将包含number. 是否可以在 javascript 中执行此操作(没有 0 填充)?

4

1 回答 1

13

你要String.fromCharCode...

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

...与以下相反String.charCodeAt

"A".charCodeAt(0); // 65
于 2013-06-12T18:32:06.233 回答