Created
January 16, 2015 03:17
-
-
Save vikikamath/ceaac32be6f04c7af5ac to your computer and use it in GitHub Desktop.
Hex 2 ASCII to String ( Thanks to responses from Stackoverflow)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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