Skip to content

Instantly share code, notes, and snippets.

@uchitwai
Forked from daboxu/guidToByteArray.md
Created October 24, 2025 10:27
Show Gist options
  • Save uchitwai/1fb8c95e442e0d351f6025f4a1109b4e to your computer and use it in GitHub Desktop.
Save uchitwai/1fb8c95e442e0d351f6025f4a1109b4e to your computer and use it in GitHub Desktop.
Convert GUID to byte array in Javascript

It is so painful for me when I found there is no code did such so simple thing on the Internet in a simple way. So I did it.

function guidToBytes(guid) {
    var bytes = [];
    guid.split('-').map((number, index) => {
        var bytesInChar = index < 3 ? number.match(/.{1,2}/g).reverse() :  number.match(/.{1,2}/g);
        bytesInChar.map((byte) => { bytes.push(parseInt(byte, 16));})
    });
    return bytes;
}

guid id format: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment