Skip to content

Instantly share code, notes, and snippets.

@vikikamath
Created January 16, 2015 03:17
Show Gist options
  • Save vikikamath/ceaac32be6f04c7af5ac to your computer and use it in GitHub Desktop.
Save vikikamath/ceaac32be6f04c7af5ac to your computer and use it in GitHub Desktop.
Hex 2 ASCII to String ( Thanks to responses from Stackoverflow)
function str2hex(str){
var arr = [];
str.split('').forEach(function(c){
arr.push(c.charCodeAt());
});
return arr;
}
function hexarr2str(arr){
var result = '';
arr.forEach(function(h){
result += String.fromCharCode(parseInt(h, 16));
});
return result;
}
// Usage: Roundtrip
// hexarr2str(str2hex("hello"))
//"hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment