Skip to content

Instantly share code, notes, and snippets.

View e-bits's full-sized avatar

Remo Inderbitzin e-bits

  • Inderbitzin Informatik GmbH
  • 6440 Brunnen, Switzerland
View GitHub Profile
@daboxu
daboxu / guidToByteArray.md
Last active February 20, 2024 23:46
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;

}