src/custom/init.c
/**
 * xtou32
 * Take a hex string and convert it to a 32bit number (max 8 hex digits).
 * The string must only contain digits and valid hex characters (and optional 0x or 0X prefix)
 * Modified from https://stackoverflow.com/a/57112610
 */
xtou32
Take a hex string and convert it to a 32bit number (max 8 hex digits).
xtou32 Take a hex string and convert it to a 32bit number ( max 8 hex digits ) .
uint32_t xtou32(const char *str, int *err)
{
    uint32_t res = 0;
    char c;
    if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
        str += 2;
    while ((c = *str++)) {
        char v;
        if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
        {
            v = ((c & 0xF) + (c >> 6)) | ((c >> 3) & 0x8);
            res = (res << 4) | (uint32_t) v;
        }
        else
        {
            *err = 1;
            return 0;
        }
    }
    *err = 0;
    return res;
}
uint32_t xtou32 ( const char * str , int * err ) { uint32_t res = 0 ; char c ; if ( str [ 0 ] == ' ' && ( str [ 1 ] == ' ' || str [ 1 ] == ' ' ) ) str += 2 ; while ( ( c = * str ++ ) ) { char v ; if ( ( c >= ' ' && c <= ' ' ) || ( c >= ' ' && c <= ' ' ) || ( c >= ' ' && c <= ' ' ) ) { v = ( ( c & 0xF ) + ( c >> 6 ) ) | ( ( c >> 3 ) & 0x8 ) ; res = ( res << 4 ) | ( uint32_t ) v ; } else { * err = 1 ; return 0 ; } } * err = 0 ; return res ; }
xtou32
 Take a hex string and convert it to a 32bit number (max 8 hex digits).
xtou32 Take a hex string and convert it to a 32bit number ( max 8 hex digits ) .