Skip to content

Instantly share code, notes, and snippets.

@kjur
Created January 4, 2015 18:12
Show Gist options
  • Select an option

  • Save kjur/cc781f50a8a5dc7fd94a to your computer and use it in GitHub Desktop.

Select an option

Save kjur/cc781f50a8a5dc7fd94a to your computer and use it in GitHub Desktop.
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