Tại sao các ký tự tiếng Anh cần ít byte hơn để biểu diễn chúng hơn ký tự trong bảng chữ cái khác?

Mục lục:

Tại sao các ký tự tiếng Anh cần ít byte hơn để biểu diễn chúng hơn ký tự trong bảng chữ cái khác?
Tại sao các ký tự tiếng Anh cần ít byte hơn để biểu diễn chúng hơn ký tự trong bảng chữ cái khác?

Video: Tại sao các ký tự tiếng Anh cần ít byte hơn để biểu diễn chúng hơn ký tự trong bảng chữ cái khác?

Video: Tại sao các ký tự tiếng Anh cần ít byte hơn để biểu diễn chúng hơn ký tự trong bảng chữ cái khác?
Video: 3 cách quét virus toàn hệ thống Windows 10 bằng Microsoft Defender - YouTube 2024, Tháng tư
Anonim
Trong khi hầu hết chúng ta có thể không bao giờ dừng lại để suy nghĩ về nó, các ký tự chữ cái không phải là tất cả cùng kích thước trong số byte cần để đại diện cho chúng. Nhưng tại sao vậy? Bài đăng Hỏi & Đáp của SuperUser hôm nay có câu trả lời cho câu hỏi của người đọc tò mò.
Trong khi hầu hết chúng ta có thể không bao giờ dừng lại để suy nghĩ về nó, các ký tự chữ cái không phải là tất cả cùng kích thước trong số byte cần để đại diện cho chúng. Nhưng tại sao vậy? Bài đăng Hỏi & Đáp của SuperUser hôm nay có câu trả lời cho câu hỏi của người đọc tò mò.

Phiên Hỏi & Đáp hôm nay đến với chúng tôi theo lịch sự của SuperUser - một phân khu của Stack Exchange, một nhóm các trang web Hỏi & Đáp do cộng đồng điều hành.

Ảnh chụp màn hình một phần ASCII Chart của Wikipedia.

Câu hỏi

Người đọc siêu người dùng khajvah muốn biết lý do tại sao các bảng chữ cái khác nhau chiếm một lượng không gian đĩa khác nhau khi được lưu:

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?

Chữ cái là chữ cái, phải không? Có thể không! Câu trả lời cho bí ẩn chữ cái này là gì?

Câu trả lời

Những người đóng góp của SuperUser Doktoro Reichard và ernie có câu trả lời cho chúng tôi. Đầu tiên, 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 considering 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 mentions the fact that perforated tape held 8 bits in a position at a time). In fact, the original ASCII scheme can be transmitted 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.

Tiếp theo là câu trả lời từ ernie:

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.

Có cái gì để thêm vào lời giải thích? Tắt âm thanh trong các ý kiến. Bạn muốn đọc thêm câu trả lời từ những người dùng Stack Exchange có hiểu biết công nghệ khác? Xem toàn bộ chuỗi thảo luận tại đây.

Đề xuất: