1. 首页 > 手机 >

汉字转unicode 汉字转unicode16进制

您好,今天小蚪来为大家解答以上的问题。汉字转unicode相信很多小伙伴还不知道,现在让我们一起来看看吧!

汉字转unicode 汉字转unicode16进制汉字转unicode 汉字转unicode16进制


汉字转unicode 汉字转unicode16进制


1、回答:是的。

2、不过可以像下面这样来作:Unicode有二字节编码(UCS-2)和四字节编码(UCS-4)两种,目前常用的二字节编码。

3、下面程序给出的是UTF-8转成Unicode(UCS-2)的函数。

4、 #include #include {int outputSize = 0; //记录转换后的Unicode字符串的字节数 ppOutput = (char )malloc(strlen(pInput) 2); //为输出字符串分配足够大的内存空间memset(ppOutput, 0, strlen(pInput) 2);while (pInput){if (pInput > 0x00 && pInput {tmp = pInput;tmp++;tmp = 0; //小端法表示,在高地址填补0{char high = pInput;pInput++;char low = pInput; if ((low & 0xC0) != 0x80) //检查是否为合法的UTF8字符表示{return -1; //如果不是则报错}tmp = (high tmp++;tmp = (high >> 2) & 0x07;}else if (((pInput) & 0xF0) == 0xE0) //处理三字节UTF8字符{char high = pInput;pInput++;char middle = pInput;pInput++;char low = pInput; if (((middle & 0xC0) != 0x80) || ((low & 0xC0) != 0x80)){return -1;} tmp = (middle tmp++;tmp = (high > 2) & 0x0F);}else //对于其他字节数的UTF8字符不进行处理{return -1;} pInput ++;tmp ++;outputSize += 2;tmp++;tmp = 0; return outputSize;} //一个调用示例int main(int argcL=, char argv){ //汉字“我”的UTF8编码是 E6 88 ,Unicode编码是 62 11char str[4] = {(char)0xE6, (char)0x88, (char)0x, (char)0x00};char uni = NULL; int num = utf8_to_unicode(str, &uni); if (num == -1){printf("Error!\n");}else{char p = uni;for (int i = 0; i {printf("%02X", p);p++;}printf("\n");} free(uni); //释放内存 return 0;}int utf8ToUnicode( char s, int bytes ) { if ( ( 0x80 & s[0] ) == 0 )//一个字节的UTF-8 { return s[0]; } int a, b; if ( ( 0xE0 & s[0] ) == 0xC0 )//两字节的UTF-8 { bytes = 2; a = ( 0x1F & s[0] ) 。

本文到这结束,希望上面文章对大家有所帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 12345678@qq.com 举报,一经查实,本站将立刻删除。

联系我们

工作日:9:30-18:30,节假日休息