My script is building a file that consists of bytes \xdd where dd – hex number.
The problem is obvious:
"\x" + "4c" != "\x4c" ;
and therefore I can generate a byte only using
huge array like
{
'00' : '\x00',
'01' : '\x01',
... etc.
}
Is there a better solution?
See
String.fromCharCodewhich can turn a Unicode codepoint (in the BMP) into the appropriate “character” (string with a length of one).Note that in JavaScript a string is a sequence of Unicode codepoints in the BMP. Characters requiring surrogate pairs are another story. The link includes a “fix” for this.
Happy coding.