目录
前言
在计算机中,我们如何表示数字,英文字母(A ~ Z / a ~ z),中文,符号(, .?<>),等各种符号呢?
- -
- 人们最终想到了对这些字符进行编码,比如在ASCII编码中,用一个字节的大小(8个bit位,故可表示的数量是 2^8 = 256个字符,但只用了 128 个,即(0 - 127))
- 比如:65 就代表 英文字母A,48 代表 数字0。
- 除此之外,还有很多 非打印字符(换行符、制表符等)以及 控制字符(退格、响铃等)控制编码。
- 本文中你将了解到:
- 常见的字符编码格式
- 字节序标记: 大端方式(Big endian) / 小端方式(Little endian)
- 带BOM是什么意思?
常见的字符编码格式
ASCII
- 单字节编码,使用一个字节的大小来表示一个字符(1Byte = 8 bit,故可表示的数量为 2^8 = 256个)到目前为止共定义了128个字符(0 - 127)。
- 单单我们中文常用的字符就不止256个,因此ASCII在全世界范围肯定是不够用的,因此后来才出来了很多扩展的编码格式。
- 如今的其他编码格式基本都兼容ASCII。即可理解为在它身上进行扩展。
ANSI
- American National Standards Institute (美国国家标准学会),由这个标准学会制订的一种编码规则。
- 使用 1 - 4 个字节来代表一个字符。ANSI在不同语言系统上代表不同的编码。不同 ANSI 编码之间互不兼容。
- 在 简体中文win系统 中代表 GBK
- 在 日文win系统 中代表 Shift_JIS
GBK / GB-2312 / GB18030
- 这几个就和我们中国密切相关了。
- GB2312:对 ANSI 的简体中文扩展。GB2312共收录了七千个字符。
- GBK:(即 国G标B 扩K展)由于GB2312支持的汉字太少而且不支持繁体中文,所以GBK对GB2312进行了扩展,以支持繁体中文和更多的字符,GBK共支持大概22000个字符。
- GB18030:在GBK的基础上又增加了藏文、蒙文、维吾尔文等主要的少数民族文字。
Unicode
- 由于(ANSI)各国的编码不同造成交流传输不便,ISO 打算废除所有的地区性编码方案,建立一个全球性的编码方案,并把所有字符都编码进去,称之为 "Universal Multiple-Octet Coded Character Set",简称 UCS(ISO10646)。
- 同时又有 unicode.org 这个组织也制定了自己的全球性编码 unicode,自从unicode2.0开始,unicode采用了与UCS相同的字库和字码。
- 现在用的是UCS-2,即2个字节编码,而UCS-4是为了防止将来2个字节不够用才开发的。
- Unicode只是一个符号集,它只规定了符号的二进制代码,却没有规定这个二进制代码应该如何存储(使用的字节数 / 定长存储 / 变长存储)。怎样存储、传输这些编码,则是由UTF来实现。
UTF
- 在可以使用ASCII表示的字符时使用Unicode并不高效,因为Unicode比ASCII占用大一倍的空间,而对ASCII来说高字节对他毫无用处。为了解决这个问题,就出现了一些中间格式的字符集,他们被称为通用转换格式,即UTF(Unicode Transformation Format)。这其中就有如UTF-8这种变长编码。而让最常出现的字符编码尽量的短,即可使得总的存储和传输代价小很多,这也是哈夫曼压缩编码的思想。
- UTF-8、UTF-16、UTF-32 都是 Unicode 的一种实现。目前使用最为广泛的就是UTF-8。这些看名字差别就是后面的 -8 / -16 / -32。意义就是处理单元的比特位数(即一次拿到 8 / 8 = 1 ; 16 / 8 = 2;32 / 8 = 4个字节进行处理)。
- UTF-8: 变长编码方式。也就是用这种编码出来不同字符的长度不一定相同。比如UTF-8表示ASCII中的字符需要1个字节,表示中文需要3个字节。
- UTF-16:变长编码方式。
- UTF-32:定长4字节编码。
字节序标记
处理单元为多个字节时(一次拿到多个字节进行处理),如果不分字节顺序的话,那么就会出现解读错误。比如我们一次要处理四个字节 12 34 56 78,这四个字节是表示 0x12 34 56 78 还是表示 0x78 56 34 12?不同的解释最终表示的值也不一样。因此就有了大端方式和小端方式之分。
大端方式(Big endian)
- 高位字节存在低位地址
- 低位字节存在高位地址
小端方式(Little endian)
- 高位字节存在高位地址
- 低位字节存在低位地址
- 显然 UTF-16 和 UTF-32 是需要区分大小端方式的,因为它们一次处理拿到的字节数不止一个。
- UTF-8 不需要区分大小端。
带BOM(签名)是什么意思?
- 在有些软件中(如VS2019),把带BOM翻译为带签名。
- 我们已经介绍了字节序的大端和小端方式,但怎么让计算机知道这段文本是大端还是小端方式呢?
- 这就需要在文件开头为BOM(Byte Order Mark)的字符来表明文件是 大端 还是 小端方式 来存取。
- 注意:BOM是Unicode标准建议的,因此 UTF-16 和 UTF-32 编码存储的文件需要带 BOM。而GB2312尽管是双字节,但是没有BOM这个概念的。因为他出生太早了,那时候还没有这个概念。GBK也是没有BOM的。
- UTF-8 不需要区分字节序,当然也就不需要 BOM。但可以用BOM来表明该文件的编码方式是UTF-8。但实际上非常不建议这样做,尽管 Unicode 标准允许在 UTF-8 中使用 BOM,但 UTF-8 带BOM,是Win基于兼容性考虑独创的格式,linux默认不兼容。
Thank you for great information. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you great posting about essential oil. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you great post. Hello Administ .Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Great post thank you. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you for great information. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Great post thank you. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
When Taylor Swift https://shake-it-off.taylor-swift-ar.com released “Shake It Off” in 2014, she had no idea how much the song would impact her life and music career.
Priyanka Chopra https://baywatch.priyankachopra-ar.com is an Indian actress, singer, film producer and model who has achieved global success.
paxlovid price: п»їpaxlovid – paxlovid for sale
Thank you great post. Hello Administ .Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Liverpool https://england.liverpool-ar.com holds a special place in the history of football in England.
Автомобили Hongqi https://hongqi-krasnoyarsk.ru в наличии – официальный дилер Hongqi Красноярск
Former 4th roundabout behind Enyo filling station,Chisco Busstop, Lekki – 8:00am, 9:45am. Be the first to know about upcoming events and things to do, sign up today! “+tmp+”:”;for(var cpTmp,custParams=decodeURIComponent(tmp).split(“&”),j=0;j”+(cpTmp=custParams.split(“=”)+”: “+cpTmp);kvHtml+=” Hookup apps can be a great place to find FWB, whether you’re looking for a more casual version of the relationship or an actual friend with whom you also happen to hook up. Apps like Tinder and Pure are more on the casual end of the spectrum, while you might check out apps like Hinge or OkCupid to find people you’d want to sleep with and hang out with. Kinky folks can also check out more community-oriented platforms such as FetLife. Moloko and to have had success with more of the best hookup sites. Caters to pay for singles and apps for instant communication. 5 best premium account. 25 best hookup sites servicing the widest net amazing hookup sites 1.
https://wiki-site.win/index.php?title=Dating_gay_app_free
Signing up with Allied Wallet will enable you to send and receive credit card payments online on a global scale. We have established relationships with banks around the world to make sure our clients have multiple options for payment processing. No matter where your company is located, you can accept payments from just about anyone living anywhere. It’s a card issued by a bank or financial institution that gives you access to money to make cashless payments. Unlike a debit card, the money accessed is borrowed, meaning it must be paid back, along with any interest and other charges like an annual fee. Different types of credit cards include rewards, low rate and low fee cards, each with varying features, benefits and costs. X Sign up card and find members near you Already have a account? Required In I am a: You sign post your profile, use advanced search, sign and receive messages absolutely free.Android App. New to truMingle? Join for free! Forgot your password? Remember me. Join the best free dating percent in the world. Welcome to truMingle! We’re a full-featured online dating site for singles.
Everything is very open and very clear explanation of issues. was truly information.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
http://paxloviddelivery.pro/# paxlovid buy
Juventus Football Club https://italy.juventus-ar.com is one of the most successful and decorated clubs in the history of Italian and world football.
Chelsea https://england.chelsea-ar.com is one of the most successful English football clubs of our time.
The history of one of France’s https://france.paris-saint-germain-ar.com most famous football clubs, Paris Saint-Germain, began in 1970, when capitalist businessmen Henri Delaunay and Jean-Auguste Delbave founded the club in the Paris Saint-Germain-en-Laye area.
Zinedine Zidane https://real-madrid.zinedine-zidane-ar.com the legendary French footballer, entered the annals of football history as a player and coach.
Travis Scott https://astroworld.travis-scott-ar.com is one of the brightest stars in the modern hip-hop industry.
buy amoxicillin 250mg: amoxicillin discount – generic amoxicillin cost
http://doxycyclinedelivery.pro/# doxycycline 50 mg cap
http://doxycyclinedelivery.pro/# doxycycline no prescription best prices
http://paxloviddelivery.pro/# paxlovid for sale
https://amoxildelivery.pro/# cost of amoxicillin 875 mg
mexican drugstore online: buying from online mexican pharmacy – mexico drug stores pharmacies
http://foruspharma.com/# pharmacies in mexico that ship to usa
pharmacy canadian: canadianpharmacyworld com – canada ed drugs
mexico pharmacies prescription drugs: reputable mexican pharmacies online – buying from online mexican pharmacy
mexico pharmacies prescription drugs: mexican mail order pharmacies – buying prescription drugs in mexico online
canadian pharmacy 365: canadian family pharmacy – onlinepharmaciescanada com
medication from mexico pharmacy mexico pharmacy buying from online mexican pharmacy
indian pharmacy: reputable indian online pharmacy – mail order pharmacy india
canadianpharmacyworld: best rated canadian pharmacy – reliable canadian pharmacy
online canadian pharmacy: legitimate canadian online pharmacies – canadian online pharmacy
rate canadian pharmacies buy prescription drugs from canada cheap best canadian pharmacy online
canadian pharmacy world: canadian pharmacy service – canadian pharmacy prices
purple pharmacy mexico price list: pharmacies in mexico that ship to usa – mexico pharmacy
canadian pharmacy 1 internet online drugstore: canadian pharmacy world – northwest pharmacy canada
http://foruspharma.com/# buying prescription drugs in mexico online
canadian pharmacy store my canadian pharmacy rx online canadian pharmacy
Jackie Chan https://karate-kid.jackiechan-ar.com was born in 1954 in Hong Kong under the name Chan Kong San.
Brazilian footballer Malcom https://al-hilal.malcom-ar.com (full name Malcom Felipe Silva de Oliveira) achieved great success in Al Hilal, one of the leading football teams in Saudi Arabia and the entire Middle East.
reputable indian pharmacies: reputable indian pharmacies – Online medicine order
reputable indian pharmacies: top 10 pharmacies in india – top online pharmacy india
canadian mail order pharmacy: buy drugs from canada – online canadian pharmacy review
pharmacy website india buy medicines online in india mail order pharmacy india
Monica Bellucci https://dracula.monica-bellucci-ar.com one of the most famous Italian actresses of our time, has a distinguished artistic career spanning many decades. Her talent, charisma, and stunning beauty made her an icon of world cinema.