UNICODE如何转换为ASCII??

羽中漫步 2007-11-27 08:56:18
比如说字符串“AB中国C北京BJ”UNICODE和ASCII如何相互转换,不能用任何库函数,单纯对字节流进行分析后转换。望高手指点!
...全文
792 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
longren331100 2010-11-25
  • 打赏
  • 举报
回复
怎么转啊
Holinan 2007-12-04
  • 打赏
  • 举报
回复
UNICODE码值都是占4个Byte,也就是类似下面参考代码的tmp = 0x1234,可以转换成两个8位的来表示.

#include <stdio.h>

int main()
{
unsigned int tmp;
unsigned char Dat[2];

tmp = 0x1234; //tmp在32位机中占4个Byte.用一个16位的数来赋值

Dat[0] = (char)((tmp>>8) & 0x00FF);//得到高8位的值 0x12 在VC中看到它的ASC码值为18
Dat[1] = (char)(tmp & 0x00FF);//得到低8位的值 0x34 在VC中看到它的ASC码值为52
return 0;
}

羽中漫步 2007-12-04
  • 打赏
  • 举报
回复
比如汉字“北”的UNICODE编码是多少呢?不同的平台UNICODE也完全一样是吗?UNICODE也没有 头的标志?
“北”表示为unsigned char是0XB1B1,UNICODE也是这个吗?
jinyt 2007-12-04
  • 打赏
  • 举报
回复
不同的平台UNICODE也完全一样是吗?
使得。他是国际标准。

UNICODE也没有 头的标志?
“北”表示为unsigned char是0XB1B1,UNICODE也是这个吗?

#
# Name: cp936 to Unicode table
# Unicode version: 2.0
# Table version: 2.01
# Table format: Format A
# Date: 1/7/2000
#
# Contact: Shawn.Steele@microsoft.com
#
# General notes: none
#
# Format: Three tab-separated columns
# Column #1 is the cp936 code (in hex)
# Column #2 is the Unicode (in hex as 0xXXXX)
# Column #3 is the Unicode name (follows a comment sign, '#')
#
# The entries are in cp936 order
#
……
0xB1B1 0x5317 #CJK UNIFIED IDEOGRAPH
……

由此可知:
北”表示为unsigned char是0XB1B1,UNICODE是0x5317
jinyt 2007-12-04
  • 打赏
  • 举报
回复
ASCII编码在汉字中有gb2312,gbk,gb18030
他们和UNICODE是没有逻辑上的对应关系的,除了查表,好像没什么方法的。
其实库函数也是这么做的,就是效率上的差别。
jinyt 2007-11-27
  • 打赏
  • 举报
回复
http://www.google.cn/search?hl=zh-CN&q=cp936+gbk&btnG=Google+%E6%90%9C%E7%B4%A2&meta=&aq=t&oq=cp936+

#
# Name: cp936 to Unicode table
# Unicode version: 2.0
# Table version: 2.01
# Table format: Format A
# Date: 1/7/2000
#
# Contact: Shawn.Steele@microsoft.com
#
# General notes: none
#
# Format: Three tab-separated columns
# Column #1 is the cp936 code (in hex)
# Column #2 is the Unicode (in hex as 0xXXXX)
# Column #3 is the Unicode name (follows a comment sign, '#')
#
# The entries are in cp936 order
#
……
把这个码表下载下来,然后写代码查表,转
独孤过儿 2007-11-27
  • 打赏
  • 举报
回复
好像不可能,ASCII是一个字节的,unicode是两个字节的,不过要是纯拷贝字节流,那肯定没问题,嘿嘿

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧