汉字utf-8转unicode
来源:互联网 发布:单片机课后答案霍孟友 编辑:程序博客网 时间:2024/05/20 18:40
#include <stdio.h>#include <string.h>#include <stdlib.h>#define u8 unsigned char#define u16 unsigned shortstatic int getUtf8ByteNumForWord(u8 firstCh){int num = 0;int temp = 0x80;while (firstCh & temp){num++;temp = temp >> 1;}if (num == 0)return 1;elsereturn num;}int utf8ToUnicode(u8 *utf8, u16 *unicodeKey){int i = 0;int j = 0;u8 firstCh = utf8[0];u8 temp[2] = {0, 0};int num = getUtf8ByteNumForWord(firstCh);switch(num) {case 1:temp[j] = utf8[i];break;case 2:temp[j + 1] = (utf8[i] >> 2) & 0x07;temp[j] = utf8[i+1] | ((utf8[i] << 6) & 0xc0);break;case 3:/* utf-8 >>>>>> unicode */temp[j + 1] = ((utf8[i] & 0x0f) << 4) | ((utf8[i + 1] >> 2) & 0x0f);temp[j] = ((utf8[i + 1] << 6) & 0xc0) | ((utf8[i + 2]) & 0x3f);break;case 4:case 5:case 6:default:break;}memcpy(unicodeKey, temp, 2);return 0;}int main(){int i, a , b ,c;u8 word_utf8[10][3];u8 print_word[3];char *stdin_st = malloc(31);u16 unicode = 0;while(1) {a = b = c = 0;fgets(stdin_st, 31, stdin);while(c < 31) {if (stdin_st[c] == '\n')break;word_utf8[a][b++] = stdin_st[c++];if (b == 3) {a++;b = 0;}}for (i = 0; i < a; i++) {utf8ToUnicode(word_utf8[i], &unicode);memcpy(print_word, word_utf8[i], 3);printf("%s=%d\n", print_word, unicode);}}return 0;}
0 0
- 汉字utf-8转unicode
- java Unicode 转 utf-8 汉字
- java Unicode 转 utf-8 汉字
- java爬取网页Unicode 转 utf-8 汉字
- java进行汉字unicode转变成utf-8汉字
- UTF-8 转 Unicode
- UTF-8 转 Unicode
- Unicode转UTF-8
- unicode转utf-8
- Unicode转utf-8
- Unicode转UTF-8
- UTF-8 转 UNIcode
- 汉字编码(【Unicode】 【UTF-8】 【Unicode与UTF-8之间的转换】 【汉字 Unicode 编码范围】【中文标点Unicode码】【GBK编码】【批量获取汉字UNICODE码】)
- c# GBK,Unicode,UTF-8编码与汉字的转换
- C语言 获取汉字unicode和utf-8编码
- python utf-8转汉字
- php unicode转utf-8
- ios Unicode 转 UTF-8
- Android如何在http头信息里设置参数
- 慕课网二次学习(六)
- Opencv 中的函数不起作用
- Sql Server优化之路
- Sizeof与Strlen的区别与联系
- 汉字utf-8转unicode
- PHP基础笔记(02)
- UItUItableView 自定义 多选和全选
- Codefoces 677C Vanya and Label (预处理/翻译)
- BatteryChargingSpecification1.2中文详解
- 嵌入式驱动程序之信号量
- Qt简单编程--给裸体的MPlayer披件衣服变成自己的播放器
- HYSBZ 3672购票
- C++实验7—特殊三位数