Last active
August 29, 2015 13:56
-
-
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.
This file contains hidden or 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 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