- ISO-8859-1编码是单字节编码,向下兼容ASCII,其编码范围是0x00-0xFF,0x00-0x7F之间完全和ASCII一 致,0x80-0x9F之间是控制字符,0xA0-0xFF之间是文字符号。
- ISO-8859-1收录的字符除ASCII收录的字符外,还包括西欧语言、希腊语、泰语、阿拉伯语、希伯来语对应的文字符号。
3、Unicode编码
- Unicode只是一个符号集,它只规定了符号的二进制代码,却没有规定这个二进制代码应该如何存储。
- 每个字符提供了一个唯一的数字编号
- Unicode 的编码方式与 ISO 10646 的通用字元集(亦称[通用字符集])(Universal Character Set,UCS)概念相对应,目前的用于实用的 Unicode 版本对应于 UCS-2,使用16位的编码空间。也就是每个字符占用2个字节。这样理论上一共最多可以表示 65,536(2的16次方) 个字符。基本满足各种语言的使用。实际上目前版本的 Unicode 尚未填充满这16位编码,保留了大量空间作为特殊使用或将来扩展。
- Unicode 的实现方式称为Unicode转换格式(Unicode Translation Format,简称为 UTF)。
- UTF-8是Unicode的实现方式之一 ,它是一种变长的编码方式。它可以使用1~4个字节表示一个符号,根据不同的符号而变化字节长度
- UTF-16编码采用16位即双字节作为编码单位,它同样是变长的编码规则
- 这就是汉子的国标码,专门用来表示汉字,是双字节编码,而英文字母和iso8859-1一致(兼容iso8859-1编码)。其中gbk编码能够用来同时表示繁体字和简体字,而gb2312只能表示简体字,gbk是兼容gb2312编码的。
编码转换测试:
try {
String str="哈哈";
String iso8859Str = new String (str.getBytes(),"iso8859-1");
System.out.println("###After the String coding iso8859-1 #### "+iso8859Str);
String utf8Str= new String(str.getBytes(),"utf-8");
System.out.println("###After the String coding utf-8 ###"+utf8Str);
String gbkStr= new String(str.getBytes(),"gb2312");
System.out.println("###After the String coding gb2312 ###"+gbkStr);
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
字符串str采用gbk编码时,结果如下:
###After the String coding iso8859-1 #### ????
###After the String coding utf-8 ###????
###After the String coding gb2312 ###哈哈
字符串str采用utf-8编码时,结果如下:
###After the String coding iso8859-1 #### ??????
###After the String coding utf-8 ###哈哈
###After the String coding gb2312 ###??????
字符串str采用iso8859-1编码时,结果如下:
###After the String coding iso8859-1 #### ??
###After the String coding utf-8 ###??
###After the String coding gb2312 ###??
-------------------------jsp编码-----------------------------