Skip to content

Instantly share code, notes, and snippets.

@sunfuze
Created April 24, 2014 09:11
Show Gist options
  • Save sunfuze/11247602 to your computer and use it in GitHub Desktop.
Save sunfuze/11247602 to your computer and use it in GitHub Desktop.
function hex2ascii(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
};
function ascii2hex(ascii) {
var tempstr = '';
for (a = 0; a < ascii.length; a = a + 1) {
var tmpChar = ascii.charCodeAt(a).toString(16);
if (tmpChar.length < 2) {
tempstr = tempstr + "0" + tmpChar;
} else {
tempstr = tempstr + tmpChar;
}
}
return tempstr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment