Quick actions

cmd+k|ctrl+k

Navigation

Languages

UUID to text

Snippet info

Language

C

Visibility

public

Author

rightfold

Created

2016-07-13T14:45:56Z

Updated

2016-07-13T14:50:21Z

#include <stdio.h>
#include <stdlib.h>

static char const hex_digits[] = {
    '0', '1', '2', '3',
    '4', '5', '6', '7',
    '8', '9', 'a', 'b',
    'c', 'd', 'e', 'f',
};

void encode_uuid(char out[static 33], char const in[static 16]) {
    for (size_t ii = 0, oi = 0; ii < 16; ii++, oi += 2) {
        out[oi    ] = hex_digits[(in[ii] & 0xF0) >> 4];
        out[oi + 1] = hex_digits[(in[ii] & 0x0F)     ];
    }
    out[32] = 0;
}

int main() {
    char uuid[16] = {0, 0xab, 2, 3, 4, 5, 6, 7, 0xda, 9, 10, 11, 12, 13, 14, 15};
    char text[33];
    encode_uuid(text, uuid);
    printf("%s\n", text);
    return 0;
}
INFO