Created
October 11, 2015 04:48
-
-
Save gimntut/c1cd8dcefe2a255cc861 to your computer and use it in GitHub Desktop.
This file contains 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 string2Bin(str) { | |
var result = []; | |
for (var i = 0; i < str.length; i++) { | |
result.push(str.charCodeAt(i)); | |
} | |
return result; | |
} | |
function bin2String(array) { | |
return String.fromCharCode.apply(String, array); | |
} | |
string2Bin('foo'); // [102, 111, 111] | |
bin2String(string2Bin('foo')) === 'foo'; // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment