I want to convert an number (integer) to a hex string
2 (0x02) to "\x02"
or
62 (0x0062) to "\x62"
How can I do that correctly?
I want to convert an number (integer) to a hex string
2 (0x02) to "\x02"
or
62 (0x0062) to "\x62"
How can I do that correctly?
You can use the to string method:
a = 64;
a.toString(16); // prints "40" which is the hex value
a.toString(8); // prints "100" which is the octal value
a.toString(2); // prints "1000000" which is the binary value
Well, it's seems that you want just to concatenate the integer with \x.
If so just to like that:
var number = 62;
var hexStr = '\x' + number.toString(16);
But you have something strange about explaining.
Note: that 62 is not the same as 0x62, 0x62 would be 98.