Created
December 19, 2016 16:13
-
-
Save vidul-nikolaev-petrov/b8b6daa5a3ab7a4d3484cafa06ecc213 to your computer and use it in GitHub Desktop.
Tiny helpers: ASCII HEX STRING
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 string2ascii(string, sep) { | |
return string.split('') | |
.map(e => e.charCodeAt(0)).join(sep ? sep : ''); | |
} | |
function string2hex(string, sep) { | |
return string.split('') | |
.map(e => e.charCodeAt(0).toString(16)).join(sep ? sep : ''); | |
} | |
function hex2string(string, sep) { | |
return string.split(/(\w{2})/g).filter(e => e) | |
.map(e => String.fromCharCode(parseInt(e, 16))).join(sep ? sep : ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment