Skip to content

Instantly share code, notes, and snippets.

@32bitkid
Created January 13, 2010 17:23
Show Gist options
  • Save 32bitkid/276380 to your computer and use it in GitHub Desktop.
Save 32bitkid/276380 to your computer and use it in GitHub Desktop.
function guidToArray(guid) {
tmp_guid = guid.replace(/-/g,"");
byteArray = new Array(tmp_guid.length/2);
for(var i = 0; i< tmp_guid.length; i+=2) { byteArray[i/2] = parseInt(tmp_guid.substr(i,2), 16) };
return byteArray;
}
Array.prototype.toGuid = function() {
a = [];
for(var i = 0; i < this.length; i++) { a[i] = (this[i] < 16) ? "0" + this[i].toString(16) : this[i].toString(16); }
a.splice(4,0,"-");
a.splice(7,0,"-");
a.splice(10,0,"-");
a.splice(13,0,"-");
return a.join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment