Skip to content

Instantly share code, notes, and snippets.

@vidul-nikolaev-petrov
Created December 19, 2016 16:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vidul-nikolaev-petrov/b8b6daa5a3ab7a4d3484cafa06ecc213 to your computer and use it in GitHub Desktop.
Save vidul-nikolaev-petrov/b8b6daa5a3ab7a4d3484cafa06ecc213 to your computer and use it in GitHub Desktop.
Tiny helpers: ASCII HEX STRING
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