Reputation: 1715
The code in this SO answer, works with latin chars.
#include <stdio.h>
void charToHex(char *a)
{
char word[17], outword[33];//17:16+1, 33:16*2+1
int i, len;
strcpy(word, a);
len = strlen(word);
if(word[len-1]=='\n')
word[--len] = '\0';
for(i = 0; i<len; i++){
sprintf(outword+i*2, "%02X", word[i]);
}
printf("%s\n", outword);
}
int main(void)
{
char ch[10]="a";
charToHex(ch);
return 0;
}
It writes 61 for "a". But if I put "ق" in ch[10], it returns FFFFFFFF82. But it should be D982. How can I get true Hex value for Arabic letters? You can try code with ideone.
Thanks.
Upvotes: 2
Views: 1245
Reputation: 379
D9 = 1101 1001. which becomes a -ve 1 byte number . try using unsigned array it will work
Upvotes: 1