/* This is the RFC2938 variant of base32, not RFC3548, Crockford's, or other newer variant. It produces an 8-byte encoded character string (plus trailing null) from a 32-bit integer input.  */
int u32_to_base32(UINT32 input, char *output)
/* This is the RFC2938 variant of base32, not RFC3548, Crockford's, or other newer variant. It produces an 8-byte encoded character string (plus trailing null) from a 32-bit integer input.  */
int u32_to_base32(UINT32 input, char *output)
{
    static const char base32hex_table[32] = {
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
        'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
        'u', 'v'
    };
    int i;
    for (i = 0; i < 7; i++) {
        output[6 - i] = base32hex_table[input & 0x1f];
        input >>= 5;
    }
    output[7] = '$';
    output[8] = '\0';    
    return 0;    
}