Skip to content

Instantly share code, notes, and snippets.

@gimntut
Created October 11, 2015 04:48
Show Gist options
  • Save gimntut/c1cd8dcefe2a255cc861 to your computer and use it in GitHub Desktop.
Save gimntut/c1cd8dcefe2a255cc861 to your computer and use it in GitHub Desktop.
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