unicode

深入理解计算机系统cp1:存储单位与编码

我怕爱的太早我们不能终老 提交于 2020-03-01 23:54:58
摘要: 理解计算机是如何存储数据的。 原文: 深入理解计算机系统cp1:存储单位与编码 作者: Chor Fundebug 经授权转载,版权归原作者所有。 1. 存储单位 位:即 bit,表示二进制位,要么是 0 ,要么是 1。它是计算机内部数据存储的最小单位。比如 11010100 共有8个二进制位,是一个8位二进制数。 字节:即 byte,它由8个二进制位构成,即 1byte=8bit,是计算机内部计量的基本单位。一个英文字符占1个字节(8位),一个汉字占2个字节(16位) 字:即word,它由若干个字节构成,是计算机内部进行数据处理和运算的基本单位。字的总的位数称为字长,不同档次的计算机字长是不一样的,比如32位机,它的1个字由4个字节构成,字长为32位,也就是说其CPU一次操作处理的实际位数是32位。同理,64位机可以处理64位。由此可见,计算机的字长越大,其性能越优越。 KB,MB:1024byte = 1KB,1024KB = 1MB。往上还有GB,TB。 PS:数据传输大多以 bit 为单位,比如我们常说的网速100M/s,M/s其实Mbit/s,也就是兆比特每秒,我们还可以写成100Mbps。 2. 编码 2.1 为什么需要编码? 计算机只能理解0和1,无法理解英文、字母、汉字和其他特殊字符,这些字符需要经过编码才能成为计算机可以理解的二进制数。

java中字符与字节的编码关系

依然范特西╮ 提交于 2020-03-01 13:10:44
一个英文字母字符存储需要1个字节。在 GB 2312 编码或 GBK 编码中,一个 汉字 字符存储需要2个 字节 。 在UTF-8编码中,一个英文字母字符存储需要1个字节,一个汉字字符储存需要3到4个字节。在UTF-16编码中,一个英文字母字符或一个汉字字符存储 都需要2个字节(Unicode扩展区的一些汉字存储需要4个字节)。在UTF-32编码中,世界上任何字符的存储都需要4个字节。 其次还要知道一点常识,就是我们在记事本等一些文本工具中 写的都是字符,没有谁会去写字节(可以写字节,但是要用具特殊的编辑器), 但是其实,我们的写的是字符,但磁盘上真实存储的是字节。 这里就出现了转换的问题,当然,这些问题记事本本身会帮助我们解决。我们打开一个记事本,然后文件--另存为,你会发现有几种存储格式供您选择, ANSI格式:就是ascii的格式 Unicode格式:采用国际通用的编码存储 Unicode big endian格式:这个和unicode有点区别,但我也不明太具体的不同 UTF-8:采用utf-8存储,看过上面的两篇文章,你会十分的了解这里介绍的编码。Utf-8,是unicode的一种实现方式。 例如我们在记事本里面输入“连通”两个字。 1.我们另存记事本的时候,采用unicode存储,那么虽然我们看到的字符还是“连通”,但是其实存储在磁盘上的字节 确实 8FDE(连)

OpenERP PyChart 中文报表模块(支持CJK语言)

↘锁芯ラ 提交于 2020-03-01 07:20:45
OpenERP PyChart Unicode Report (Support CJK Font) 作者:wangbuke@gmail.com 源码托管地址: https://github.com/buke/openerp-pychart-unicode-report OpenERP 官方APP下载地址: http://apps.openerp.com/addon/8009 支持pychart中文报表,如“库存预测”、“工作中心负载” 等报表。 模块原理 让pychart 生成svg 文件,然后用cairosvg 模块生成PDF报表。 依赖模块 python-cairo python-cairosvg Debian/Ubuntu安装方法: $ su apt-get install python-cairo python-cairosvg 安装与设置 1、安装字体 复制您所用的字体文件,如simsun.ttc 到系统目录下。 debian/ubuntu: $ sudo cp simsun.ttc /usr/share/fonts windows : C:\> copy simsun.ttc c:/windows/fonts 2、配置pychart 报表字体 默认使用宋体 修改openerp 配置文件 openerp-server.conf , 添加以下参数: pychart

How do I load a UTF16-encoded text file in Julia?

徘徊边缘 提交于 2020-03-01 03:31:24
问题 I have a text file I am (pretty sure) is encoded in UTF16, but I don't know how to load it in Julia. Do I have to load it as bytes and then convert with UTF16String ? 回答1: The simplest way is to read it as bytes and then convert: s = open(filename, "r") do f utf16(readbytes(f)) end Note that utf16 also checks for a byte-order-mark (BOM), so it will deal with endianness issues and won't include the BOM in the resulting s . If you really want to avoid making a copy of the data, and you know it

php artisan migrate时出现 SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes解决办法

强颜欢笑 提交于 2020-02-29 22:51:55
在测试队列中运用artisan命令行 php artisan queue:table php artisan migrate时出现 SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes Change database.php which is in config folder where it says 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', I changed these to 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 来源: https://www.cnblogs.com/kangshuai/p/12386397.html

C++字符类型总结区别wchar_t,char,WCHAR

℡╲_俬逩灬. 提交于 2020-02-29 07:48:40
转至:http://www.360doc.com/content/12/0807/01/9290626_228750141.shtml 1.区别wchar_t,char,WCHAR   ANSI:即 char,可用字符串处理函数:strcat( ),strcpy( ), strlen( )等以str打头的函数。   UNICODE:wchar_t是Unicode字符的数据类型,它实际定义在里:   typedef unsigned short wchar_t;   另外,在头文件中有这样的定义:typedef wchar_t WCHAR; 所以WCHAR实际就是wchar_t   wchar_t 可用字符串处理函数:wcscat(),wcscpy(),wcslen()等以wcs打头的函数。为了让编译器识别Unicode字符串,必须以在前面加一个“L”,例如: wchar_t *szTest=L"This is a Unicode string."; 2.TCHAR   在C语言里面提供了 _UNICODE宏(有下划线),在Windows里面提供了UNICODE宏(无下划线),只要定了_UNICODE宏和UNICODE宏,系统就会自 动切换到UNICODE版本,否则,系统按照ANSI的方式进行编译和运行。只定义了宏并不能实现自动的转换,他还需要一系列的字符定义支持。 1. TCHAR

how std::u8string will be different from std::string?

落爺英雄遲暮 提交于 2020-02-27 22:19:50
问题 If I have a string: std::string s = u8"你好"; and in C++20, std::u8string s = u8"你好"; how std::u8string will be different from std::string ? 回答1: Since the difference between u8string and string is that one is templated on char8_t and the other on char , the real question is what is the difference between using char8_t -based strings vs. char -based strings. It really comes down to this: type-based encoding. Any char -based string ( char* , char[] , string , etc) may be encoded in UTF-8. But

absent std::u8string in C++11

北城余情 提交于 2020-02-27 22:19:17
问题 Why C++11 provides std::u16string and std::u32string and not std::u8string ? We need to implement the utf-8 encoding or using additional libraries? 回答1: C++20 adds char8_t and std::u8string. According to the proposal, the rationale is: UTF-8 is the only text encoding mandated to be supported by the C++ standard for which there is no distinct code unit type. Lack of a distinct type for UTF-8 encoded character and string literals prevents the use of overloading and template specialization in

absent std::u8string in C++11

梦想的初衷 提交于 2020-02-27 22:17:17
问题 Why C++11 provides std::u16string and std::u32string and not std::u8string ? We need to implement the utf-8 encoding or using additional libraries? 回答1: C++20 adds char8_t and std::u8string. According to the proposal, the rationale is: UTF-8 is the only text encoding mandated to be supported by the C++ standard for which there is no distinct code unit type. Lack of a distinct type for UTF-8 encoded character and string literals prevents the use of overloading and template specialization in

mysql 插入数据之半全角

怎甘沉沦 提交于 2020-02-27 21:23:49
一、表里有一个字段code,脚本如下: `code` varchar(32) COLLATE utf8_unicode_ci NOT NULL COMMENT '款式代码', PRIMARY KEY (`code`) USING BTREE 备注:主键,值不能重复。 二、插入数据 'I18FW09-1' ,'I18FW09-1',注意第一个值半角,第二值全角。 报异常:值“I18FW09-1”重复插入。 三、排查原因 类型utf8_unicode_ci ,在插入表得时候,会把全角转换为半角,导致重复。 四、解决办法 使用utf8_geneal_ci,或去掉COLLATE utf8_unicode_ci 来源: oschina 链接: https://my.oschina.net/u/2292306/blog/3164205