Any easy way of doing this other than doing it manually (i.e.
going character by character and building up the number)

StrIToH, in the docs.

Oops. Another case of reading quickly but not too thoroughly. Ignore that (useless) advice.


Instead, here's something from RegCode that converts the 1st and last 5 chars of a string into a HEX string, separated by colons, and adds a checksum. You should be able to adapt it pretty easily.

Regards,
Steve Mann
---
steve-at-slorevo.com
Available for Contract Work

unsigned char *regCode(unsigned char *user, Boolean nameOnly)
{
    static unsigned char name[11];
    static char hex[] = "0123456789ABCDEF";
    int len;
    int c=0, n=0, idx=0, i;
    unsigned char checkSum = 0;

len=StrLen((const char *)user);

    for(i=0;i<MIN(len,10);i++) {
        junk[c++] = hex[user[idx]/16];
        junk[c++] = hex[user[idx]%16];
        junk[c++] = ':';
        name[n++] = user[idx];
        checkSum += user[idx++];
        if(len > 10 && idx == 5)
            idx = len - 5;
    }

    junk[c++] = hex[checkSum/16];
    junk[c++] = hex[checkSum%16];
    junk[c] = '\0';
    name[n] = '\0';

    if(nameOnly)
        return name;
    else
        return junk;
}

Regards,
Steve Mann

--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to