如何将hex转换为阿拉伯语字符串? [英] how to convert hex to arabic string ?

查看:166
本文介绍了如何将hex转换为阿拉伯语字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助编写一个函数来将十六进制转换为阿拉伯语字符串



到示例获取字符串:D8B1D8B5D98AD8AFD8A7D984D8B1D982D985并返回:رصيدالرقمin english-(余额图)。

只有c代码

谢谢

I need help writing a function to convert hex to arabic string

to Example get string this : "D8B1D8B5D98AD8AFD8A7D984D8B1D982D985" and return this : رصيد الرقم in english-(Balance figure).
only c code
Thanks

推荐答案

类似:

Something like:
char* hex = "D8B1D8B5D98AD8AFD8A7D984D8B1D982D985";
wchar_t* arabic;
int hi, ai, word, nibble;

arabic = (wchar_t*)malloc(strlen(hex) / 2 + 1);
word = 0;
for (hi = 0, ai = 0; hex[hi] != '\0'; ++hi)
{
    nibble = hex[hi];
    if (nibble >= 'A')
    {
        nibble -= 'A';
        nibble += 10;
    }
    else
    {
        nibble -= '0';
    }
    word <<= 4;
    word |= nibble;
    if ((hi & 3) == 3)
    {
        arabic[ai++] = word;
        word = 0;
    }
}
arabic[ai] = L'\0';



使用调试器逐步完成此操作,以查看它如何转换和构建Unicode字符串。如果您需要UTF8的结果,那么您可以根据需要修改代码。


Step through this with your debugger to see how it converts and builds the Unicode string. If you need the result in UTF8 then you can modifiy the code as required.


这篇关于如何将hex转换为阿拉伯语字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆