Beispiel #1
0
// convert hex to unsigned long long
unsigned long long hextoulonglong(BYTE *hex)
{
    BYTE tmp[64];
    
    if(hextobinarray(tmp, hex) != 64)
        return 0L;
    return binarraytoulonglong(tmp, 64);
}
Beispiel #2
0
// convert fdxb 128 bit binary array to human readable UID
// format is ADCCCCIIIIIIIIIIII where A is 'A' or '0' for animal / non-animal,
// D is 'D' or '0' for Data block available / No data available, 
// CCCC is ISO-3166 country code or ICAR.ORG manufacturer code
// IIIIIIIIIIII is national ID
BOOL hdx_hex_to_uid(BYTE *uid, BYTE *hex)
{
    BYTE tmp[128];
    unsigned int country;
    unsigned long long id;


    // strip headers etc.
    if(!fdxb_hex_to_bin(tmp, hex))
        return FALSE;

    // reverse binary
    string_reverse(tmp, 64);

    // output animal flag
    if(tmp[0])
        uid[0]= 'A';
    else
        uid[0]= '0';

    // output data flag
    if(tmp[15])
        uid[1]= 'D';
    else
        uid[1]= '0';

    // output country/icar code
    country= binarraytoint(&tmp[16], 10);
    sprintf(&uid[2], "%04u", country);

    // output national ID
    id= binarraytoulonglong(&tmp[26], 38);
    sprintf(&uid[6], "%012llu", id);

    return TRUE;
}