ASCII to Hex in JavaScript
This JavaScript will add a method to the String object, that converts the ASCII string to a hex string consisting of the equivalent character codes for each character in the String.
String.prototype.toHex = function() {
return this.replace(/[\s\S]/g, function(s) {
return parseInt(s.charCodeAt()).toString(16);
});
};
Note that hex is base 16 and ASCII is based 256 so the hex string is a longer.
I recently had to save a password in hex (Hexadecimal) instead of plain ASCII since the software that came with my Netgear USB Wireless Adapter didn’t like the ASCII version for some reason.
So for example if your password is “joe”, then to convert it to the Hex equivalent would be:
'joe'.toHex()
Oddly, my computer (Vista) took the Hex password, while the printer took the ASCII version and my friends Windows 7 took the Hex.