Created
January 4, 2015 18:12
-
-
Save kjur/cc781f50a8a5dc7fd94a to your computer and use it in GitHub Desktop.
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 hextouint8a(hexString) { | |
| if (hexString.length % 2 != 0) | |
| throw "Invalid hexString"; | |
| var arrayBuffer = new Uint8Array(hexString.length / 2); | |
| for (var i = 0; i < hexString.length; i += 2) { | |
| var byteValue = parseInt(hexString.substr(i, 2), 16); | |
| if (byteValue == NaN) | |
| throw "Invalid hexString"; | |
| arrayBuffer[i/2] = byteValue; | |
| } | |
| return arrayBuffer; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment