Skip to content

Instantly share code, notes, and snippets.

Created May 12, 2014 16:52
Show Gist options
  • Save anonymous/c6dff14fd6ce75dc9a35 to your computer and use it in GitHub Desktop.
Save anonymous/c6dff14fd6ce75dc9a35 to your computer and use it in GitHub Desktop.
strToCodes.coffee
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 == "d" # i.e. "\n"
pos++
result.join(' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment