為什麼英語字元比其他字母表中的字元需要更少的位元組來表示它們?

雖然我們大多數人可能從來沒有停下來思考過這個問題,但字母字元在表示它們所需的位元組數上並不完全相同。但為什麼呢?今天的超級使用者問答帖子回答了一位好奇的讀者的問題。...

為什麼英語字元比其他字母表中的字元需要更少的位元組來表示它們?

雖然我們大多數人可能從來沒有停下來思考過這個問題,但字母字元在表示它們所需的位元組數上並不完全相同。但為什麼呢?今天的超級使用者問答帖子回答了一位好奇的讀者的問題。

今天的問答環節是由SuperUser提供的,SuperUser是Stack Exchange的一個分支,是一個由社群驅動的問答網站分組。

維基百科提供的部分ASCII圖表截圖。

問題

超級使用者閱讀器khajvah想知道為什麼不同的字母表在儲存時佔用不同的磁碟空間:

When I put ‘a’ in a text file and save it, it makes it 2 bytes in size. But when I put a character like ‘ա’ (a letter from the Armenian alphabet) in, it makes it 3 bytes in size.

What is the difference between alphabets on a computer? Why does English take up less space when saved?

字母就是字母,對吧?也許不是!這個按字母順序排列的謎的答案是什麼?

答案

超級使用者貢獻者Doktoro Reichard和ernie為我們提供了答案。首先,Doktoro Reichard:

One of the first encoding schemes to be developed for use in mainstream computers is the ASCII (American Standard Code for Information Interchange) standard. It was developed in the 1960s in the United States.

The English alphabet uses part of the Latin alphabet (for instance, there are few accented words in English). There are 26 individual letters in that alphabet, not c***idering case. And there would also have to exist the individual numbers and punctuation marks in any scheme that pretends to encode the English alphabet.

The 1960s was also a time when computers did not have the amount of memory or disk space that we have now. ASCII was developed to be a standard representation of a functional alphabet across all American computers. At the time, the decision to make every ASCII character 8 bits (1 byte) long was made due to technical details of the time (the Wikipedia article menti*** the fact that perforated tape held 8 bits in a position at a time). In fact, the original ASCII scheme can be tran**itted using 7 bits, and the eighth could be used for parity checks. Later developments expanded the original ASCII scheme to include several accented, mathematical, and terminal characters.

With the recent increase of computer usage across the world, more and more people from different languages had access to a computer. That meant that, for each language, new encoding schemes had to be developed, independently from other schemes, which would conflict if read from different language terminals.

Unicode came into being as a solution to the existence of different terminals by merging all possible meaningful characters into a single abstract character set.

UTF-8 is one way to encode the Unicode character set. It is a variable-width encoding (i.e. different characters can have different sizes) and it was designed for backwards compatibility with the former ASCII scheme. As such, the ASCII character set will remain one byte in size whilst any other characters are two or more bytes in size. UTF-16 is another way to encode the Unicode character set. In comparison to UTF-8, characters are encoded as either a set of one or two 16-bit code units.

As stated in other comments, the ‘a’ character occupies a single byte while ‘ա’ occupies two bytes, denoting a UTF-8 encoding. The extra byte in the original question was due to the existence of a newline character at the end.

接下來是厄尼的回答:

1 byte is 8 bits, and can thus represent up to 256 (2^8) different values.

For languages that require more possibilities than this, a simple 1 to 1 mapping can not be maintained, so more data is needed to store a character.

Note that generally, most encodings use the first 7 bits (128 values) for ASCII characters. That leaves the 8th bit, or 128 more values for more characters. Add in accented characters, Asian languages, Cyrillic, etc. and you can easily see why 1 byte is not sufficient for holding all characters.


有什麼要補充的解釋嗎?在評論中發出聲音。想從其他精通技術的Stack Exchange使用者那裡瞭解更多答案嗎?在這裡檢視完整的討論主題。

  • 發表於 2021-04-11 10:17
  • 閱讀 ( 37 )
  • 分類:網際網路

你可能感興趣的文章

燒焦(char)和瓦查爾(varchar)的區別

...char是最常用的。本文將解釋這兩種資料型別char和varchar是什麼以及它們之間的區別。 什麼是燒焦(char)? char的ISO定義是字元,char資料型別用於儲存字元。Char(n)可以儲存n個固定大小的字元。字元(n)可以容納的最大字元數為2...

  • 發佈於 2020-10-24 09:19
  • 閲讀 ( 35 )

漢字(kanji)和平假名(hiragana)的區別

...假名和漢字。人們可以透過它們的外觀和用法來區分這些字母表。平假名和片假名統稱為假名,都包含47個具有不同語音的字元。有些漢字看起來很像,甚至有相同的發音,雖然用法不同,但是隻有一個日本本土的人才能分辨出...

  • 發佈於 2020-11-02 19:39
  • 閲讀 ( 35 )

瓦查爾(varchar)和女巫(nvarchar)的區別

...料組成,資料由資料型別定義。資料型別告訴列可以包含什麼型別的值。資料庫表中的每一列都必須具有名稱和資料型別。今天,在資料庫設計中有許多可用的資料型別。在這些資料型別中,varchar和nvarchar用於儲存字串字元。Var...

  • 發佈於 2020-11-03 03:12
  • 閲讀 ( 46 )

如何在linux下用任何語言編寫

...配備了英文鍵盤,所以對於說英語的人和他們26個字母的字母表來說,建立文字似乎是最基本的。但是考慮像日語這樣的語言,它有超過10000個字元。如何使用只有101(或105,但肯定不是10000)個鍵的鍵盤輸入這些內容? ...

  • 發佈於 2021-03-15 04:25
  • 閲讀 ( 43 )

如何鍵入重音字元沒有惱人的alt程式碼

...言”來開啟“語言和區域設定”。在“語言”下,單擊“英語(美國)”,然後單擊“選項”。 ...

  • 發佈於 2021-03-17 00:35
  • 閲讀 ( 31 )

如何使用這9個函式在php中操作文字

...語言(包括PHP)中的基本標量型別之一。它們表示從單個字元到整個文件的文字資料。 ...

  • 發佈於 2021-03-27 01:14
  • 閲讀 ( 47 )

ascii和unicode文字之間有什麼區別?

ASCII和Unicode都是指文字的數字表示的標準,特別是組成文字的字元。然而,這兩個標準有著顯著的不同,許多屬性反映了它們各自的創作順序。 ...

  • 發佈於 2021-03-28 12:00
  • 閲讀 ( 43 )

電子郵件和表情符號:unicode如何幫助我們線上交流

...爾·莫爾斯和阿爾弗雷德·維爾出現,人們才能夠把英語字母表中的26個字母和10個阿拉伯數字全部發送出去。 ...

  • 發佈於 2021-03-28 18:08
  • 閲讀 ( 44 )

什麼是ascii文字?它是如何使用的?

... ASCII是區分大小寫的,這意味著它代表52個英文字母表中的大小寫字母。除了相同的10位數字,這大約是所用空間的一半。 ...

  • 發佈於 2021-03-29 03:18
  • 閲讀 ( 47 )

如何在linux上使用fold命令

...規則:瞭解你的敵人。讓我們來定義它。一行文字到底是什麼?它是由字母、數字、符號和空格組成的一系列字元,以一個表示“開始新行”的特殊位元組結尾。在Linux和Unix中,換行符(也稱為換行符)用作行尾指示符。這是一...

  • 發佈於 2021-04-02 16:13
  • 閲讀 ( 39 )
城牆上的太陽
城牆上的太陽

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦