Created
June 20, 2012 16:24
-
-
Save atdt/2960770 to your computer and use it in GitHub Desktop.
stringToByteArray
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 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