Skip to content

Instantly share code, notes, and snippets.

@jremmen
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jremmen/9045358 to your computer and use it in GitHub Desktop.
Save jremmen/9045358 to your computer and use it in GitHub Desktop.
A couple of javascript one liners for easily converting text message to binary and binary messages to text.
function text2bin(msg) { return msg.split('').map(function(x) { var b = x.charCodeAt(0).toString(2); return Array(9 - b.length).join(0) + b; }).join(''); }
function bin2text(bin) { return bin.match(/(.{1,8})/g).map(function(x) { return String.fromCharCode(parseInt(x, 2)) }).join(''); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment