User:Beginner 25/UFT-16
A Wikipédiából, a szabad lexikonból.
| Unicode |
|---|
Kódolások
|
| UCS |
| Elhelyezkedés |
| Kétirányú szöveg |
| BOM |
| Han egységesítés |
| Unicode és HTML |
| Unicode és e-mail |
| Unicode fontok |
Az számítástechnikában az UTF-16 egy változó hosszúságú (16 vagy 32 bites) karakter kódolási módszer. Képes kezelni a teljes Unicode Alap Többnyelvű Lapot (Basic Multilingual Plane - BMP) pontosan két byte-on, és minden másik lapot pontosan négy byte-on. UCS-2 egy fix hosszúságú (16 bites) részhalmaza az UTF-16-nak, de csak az alap többnyelvű lap kezelésére képes.
Az UTF-16-ot hivatalosan az ISO/IEC 10646-1 Q melléklete (Annex Q) határozza meg. A Unicode szabvány 3.0-ás vagy magasabb változatai, illetve az IETF RFC 2781 is laírja az UFT-16-ot.
UTF-16 represents a character that has been assigned within the lower 65536 code points of Unicode or ISO/IEC 10646 as a single code value equivalent to the character's code point: 0 for 0, hexadecimal FFFD for FFFD, for example.
Tartalomjegyzék |
[szerkesztés] Method for code points in Plane 1, Plane 2
UTF-16 represents a character above hexadecimal FFFF using a pair of 16-bit words, known as a surrogate pair, using "flag" code values from the range D800–DFFF. For example, the character at code point hexadecimal 10000 becomes the code value sequence D800 DC00, and the character at hexadecimal 10FFFD, the upper limit of Unicode, becomes the code value sequence DBFF DFFD. Unicode and ISO/IEC 10646 do not assign characters to any of the code points in the D800–DFFF range, so an individual code value from a surrogate pair does not ever represent a character.
[szerkesztés] Nagy a végén/Kicsi a végén
These code values are then serialized as 16-bit words, one word per code value. Mivel ezeknek a szavaknak az endianitása a számítógép architektúráktól függően sokféle lehet, az UTF-16 meghatározott három kódolási sémát: UTF-16, UTF-16LE, és UTF-16BE.
The UTF-16 encoding scheme mandates that the byte order must be declared by prepending a Byte Order Mark before the first serialized character. This BOM is the encoded version of the Zero-Width No-Break Space character, Unicode number FEFF in hex, manifesting as the byte sequence FE FF for big-endian, or FF FE for little-endian. A BOM at the beginning of UTF-16 encoded data is considered to be a signature separate from the text itself; it is for the benefit of the decoder.
The UTF-16LE and UTF-16BE encoding schemes are identical to the UTF-16 encoding scheme, but rather than using a BOM, the byte order is implicit in the name of the encoding (LE for little-endian, BE for big-endian). A BOM at the beginning of UTF-16LE or UTF-16BE encoded data is not considered to be a BOM; it is part of the text itself.
The IANA has approved UTF-16, UTF-16BE, and UTF-16LE for use on the Internet, by those exact names (case insensitively). The aliases UTF_16 or UTF16 may be meaningful in some programming languages or software applications, but they are not standard names in Internet protocols.
[szerkesztés] Major operating system usage
UTF-16 is the native internal representation of text in the Microsoft Windows NT/Windows 2000/Windows XP/Windows CE, Qualcomm BREW, and Symbian operating systems; the Java, Ecmascript including and .NET bytecode environments; Mac OS X's Cocoa and Core Foundation frameworks; and the Qt cross-platform graphical widget toolkit.
[szerkesztés] UCS-2
UCS-2 is an obsolete specification that can only encode the BMP, and consequently has been superseded by UTF-16. In some materials, the terms UCS-2 and UTF-16 are erroneously conflated and used interchangeably; UTF-16 is often mislabeled UCS-2.
NT systems prior to Windows 2000 only support UCS-2.
[szerkesztés] Examples
| kód érték | karakter | UTF-16 kód érték(ek) | glifa* |
|---|---|---|---|
| 122 (hex 7A) | kis Z (Latin) | 007A | z |
| 27700 (hex 6C34) | víz (kínaiul) | 6C34 | 水 |
| 119070 (hex 1D11E) | zenei G kulcs | D834 DD1E | 𝄞 |
| "水 z 𝄞" (víz, z, G kulcs), UTF-16 szerint kódolva | ||
|---|---|---|
| Kódolási forma | endianitás | Byte sorozat |
| UTF-16LE | kicsi a végén | 34 6C, 7A 00, 34 D8 1E DD |
| UTF-16BE | nagy a végén | 6C 34, 00 7A, D8 34 DD 1E |
| UTF-16 | kicsi a végén, BOM-mal | FF FE, 34 6C, 7A 00, 34 D8 1E DD |
| UTF-16 | nagy a vgén, BOM-mal | FE FF, 6C 34, 00 7A, D8 34 DD 1E |
* Megfelelő fontok és szoftver szükséges, hogy a helyes jelek (glifák) jelenjenek meg.
[szerkesztés] Példa a UTF-16 kódolási eljárásra
The character at code point U+64321 (hexadecimal) is to be encoded in UTF-16. Since it is above U+FFFF, it must be encoded with a surrogate pair, as follows:
v = 0x64321
v′ = v - 0x10000
= 0x54321
= 0101 0100 0011 0010 0001
vh = 0101010000 // v′ felső 10 bitje
vl = 1100100001 // v′ alsó 10 bitje
w1 = 0xD800 // az eredmény 1. szavának feltöltése az alsó korláttal
w2 = 0xDC00 // az eredmény 2. szavának feltöltése a felső korláttal
w1 = w1 | vh
= 1101 1000 0000 0000 |
01 0101 0000
= 1101 1001 0101 0000
= 0xD950 // az eredmény 1. szava
w2 = w2 | vl
= 1101 1100 0000 0000 |
11 0010 0001
= 1101 1111 0010 0001
= 0xDF21 // az eredmény 2. szava
A korrekt UTF-16 kódolás szerint a karakteret a következő szavak sorozata írja le:
0xD950 0xDF21
Mivel a karakter U+FFFF felett van, ezért UCS-2-ben nem kódolható.

