Skip to content

Instantly share code, notes, and snippets.

@tekwiz
Forked from anonymous/strToCodes.coffee
Last active August 29, 2015 14:01
Show Gist options
  • Save tekwiz/42d13ef3b45f2d1e822d to your computer and use it in GitHub Desktop.
Save tekwiz/42d13ef3b45f2d1e822d to your computer and use it in GitHub Desktop.
strToCodes
strToCodes = (str) ->
result = new Array(str.length)
pos = 0
while pos < str.length
c = str.charCodeAt(pos).toString(16)
result[pos] = if c.length % 2 == 1 then "x0"+c else "x"+c
result[pos] += "\n" if c == "a" # i.e. "\n"
pos++
result.join(' ')
function strToCodes(str) {
var c, pos = 0, result = new Array(str.length);
while (pos < str.length) {
c = str.charCodeAt(pos).toString(16);
result[pos] = c.length % 2 === 1 ? "x0" + c : "x" + c;
if (c === "a") {
result[pos] += "\n";
}
pos++;
}
return result.join(' ');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment