Skip to content

Instantly share code, notes, and snippets.

@atdt
Created June 20, 2012 16:24
Show Gist options
  • Select an option

  • Save atdt/2960770 to your computer and use it in GitHub Desktop.

Select an option

Save atdt/2960770 to your computer and use it in GitHub Desktop.
stringToByteArray
function stringToByteArray( str ) {
var codepoint, stack, bytes = [];
for ( var i = 0; i < str.length; i++ ) {
codepoint = str.charCodeAt( i );
stack = [];
do {
// Get 8 lowest bits of character g
stack.unshift( codepoint & 0xff );
} while ( codepoint >>= 8 );
bytes = bytes.concat( stack );
}
return bytes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment