Dear all,
I have my application that reads string initialized with an
hexadecimal value (ex. char unsigned *s="702570534A458BEF"), and a
function that takes an hexadecimal as input.
I want to convert s to hexadecimal, I do:
int i;
for (i=0; i<strlen(s); i++)
{
unsigned char t1, t2;
if (s[i] >= '0' && s[i] <= '9') {
t1=s[i] - '0';
} else if (s[i] >= 'A' && s[i] <= 'F') {
t1=s[i] - 'A' +10;
} else if (s[i] >= 'a' && s[i] <= 'f') {
t1=s[i] - 'a' +10;
}
if (s[i+1] >= '0' && s[i+1] <= '9') {
t1=s[i+1] - '0';
} else if (s[i+1] >= 'A' && s[i+1] <= 'F') {
t1=s[i+1] - 'A' +10;
} else if (s[i+1] >= 'a' && s[i+1] <= 'f') {
t1=s[i+1] - 'a' +10;
}
s[i/2] = (unsigned char) ((t1 << 4) + t2);
}
I have also unsigned char B that stores a binary value. I need to
convert it to hexadecimal, I do:
char *table = "0123456789abcdef";
int i;
for (i=0; i<strlen(B); i++)
{
B[2*i+1] = table[B[i] & 0xf];
B[2*i] = table[(B[i] & 0xf0) >> 4];
}
The above two converts work correctly. Does OpenSSL already implement
a better way to do the above convert?
Best regards,
--
Badra
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]