Variable-width encoding

Short description: Type of character encoding scheme

A variable-width encoding is a type of character encoding scheme in which codes of differing lengths are used to encode a character set (a repertoire of symbols) for representation, usually in a computer.[1][lower-alpha 1] Most common variable-width encodings are multibyte encodings, which use varying numbers of bytes (octets) to encode different characters. (Some authors, notably in Microsoft documentation, use the term multibyte character set, which is a misnomer, because representation size is an attribute of the encoding, not of the character set.)

Early variable width encodings using less than a byte per character were sometimes used to pack English text into fewer bytes in adventure games for early microcomputers. However disks (which unlike tapes allowed random access allowing text to be loaded on demand), increases in computer memory and general purpose compression algorithms have rendered such tricks largely obsolete.

Multibyte encodings are usually the result of a need to increase the number of characters which can be encoded without breaking backward compatibility with an existing constraint. For example, with one byte (8 bits) per character, one can encode 256 possible characters; in order to encode more than 256 characters, the obvious choice would be to use two or more bytes per encoding unit, two bytes (16 bits) would allow 65,536 possible characters, but such a change would break compatibility with existing systems and therefore might not be feasible at all.[lower-alpha 2]

## Contents

* 1 General structure
* 2 CJK multibyte encodings
* 3 Unicode variable-width encodings
* 4 See also
* 5 Notes
* 6 References

## General structure

Since the aim of a multibyte encoding system is to minimise changes to existing application software, some characters must retain their pre-existing single-unit codes, even while other characters have multiple units in their codes. The result is that there are three sorts of units in a variable-width encoding: singletons, which consist of a single unit, lead units, which come first in a multiunit sequence, and trail units, which come afterwards in a multiunit sequence. Input and display software obviously needs to know about the structure of the multibyte encoding scheme, but other software generally doesn't need to know if a pair of bytes represent two separate characters or just one character.

For example, the four character string "I♥NY" is encoded in UTF-8 like this (shown as hexadecimal byte values): 49 E2 99 A5 4E 59. Of the six units in that sequence, 49, 4E, and 59 are singletons (for I, N, and Y), E2 is a lead unit and 99 and A5 are trail units. The heart symbol is represented by the combination of the lead unit and the two trail units.

UTF-8 makes it easy for a program to identify the three sorts of units, since they fall into separate value ranges. Older variable-width encodings are typically not as well-designed, since the ranges may overlap. A text processing application that deals with the variable-width encoding must then scan the text from the beginning of all definitive sequences in order to identify the various units and interpret the text correctly. In such encodings, one is liable to encounter false positives when searching for a string in the middle of the text. For example, if the hexadecimal values DE, DF, E0, and E1 can all be either lead units or trail units, then a search for the two-unit sequence DF E0 can yield a false positive in the sequence DE DF E0 E1, which consists of two consecutive two-unit sequences. There is also the danger that a single corrupted or lost unit may render the whole interpretation of a large run of multiunit sequences incorrect. In a variable-width encoding where all three types of units are disjunct, string searching always works without false positives, and (provided the decoder is well written) the corruption or loss of one unit corrupts only one character.

## CJK multibyte encodings

The first use of multibyte encodings was for the encoding of Chinese, Japanese and Korean, which have large character sets well in excess of 256 characters. At first the encoding was constrained to the limit of 7 bits. The ISO-2022-JP, ISO-2022-CN and ISO-2022-KR encodings used the range 21–7E (hexadecimal) for both lead units and trail units, and marked them off from the singletons by using ISO 2022 escape sequences to switch between single-byte and multibyte mode. A total of 8,836 (94×94) characters could be encoded at first, and further sets of 94×94 characters with switching. The ISO 2022 encoding schemes for CJK are still in use on the Internet. The stateful nature of these encodings and the large overlap make them very awkward to process.

On Unix platforms, the ISO 2022 7-bit encodings were replaced by a set of 8-bit encoding schemes, the Extended Unix Code: EUC-JP, EUC-CN and EUC-KR. Instead of distinguishing between the multiunit sequences and the singletons with escape sequences, which made the encodings stateful, multiunit sequences were marked by having the most significant bit set, that is, being in the range 80–FF (hexadecimal), while the singletons were in the range 00–7F alone. The lead units and trail units were in the range A1 to FE (hexadecimal), that is, the same as their range in the ISO 2022 encodings, but with the high bit set to 1. These encodings were reasonably easy to work with provided all your delimiters were ASCII characters and you avoided truncating strings to fixed lengths, but a break in the middle of a multibyte character could still cause major corruption.

On the PC (DOS and Microsoft Windows platforms), two encodings became established for Japanese and Traditional Chinese in which all of singletons, lead units and trail units overlapped: Shift-JIS and Big5 respectively. In Shift-JIS, lead units had the range 81–9F and E0–FC, trail units had the range 40–7E and 80–FC, and singletons had the range 21–7E and A1–DF. In Big5, lead units had the range A1–FE, trail units had the range 40–7E and A1–FE, and singletons had the range 21–7E (all values in hexadecimal). This overlap again made processing tricky, though at least most of the symbols had unique byte values (though strangely the backslash does not).

## Unicode variable-width encodings

The Unicode standard has two variable-width encodings: UTF-8 and UTF-16 (it also has a fixed-width encoding, UTF-32). Originally, both the Unicode and ISO 10646 standards were meant to be fixed-width, with Unicode being 16-bit and ISO 10646 being 32-bit.[citation needed] ISO 10646 provided a variable-width encoding called UTF-1, in which singletons had the range 00–9F, lead units the range A0–FF and trail units the ranges A0–FF and 21–7E. Because of this bad design, similar to Shift JIS and Big5 in its overlap of values, the inventors of the Plan 9 operating system, the first to implement Unicode throughout, abandoned it and replaced it with a much better designed variable-width encoding for Unicode: UTF-8, in which singletons have the range 00–7F, lead units have the range C0–FD (now actually C2–F4, to avoid overlong sequences and to maintain synchronism with the encoding capacity of UTF-16; see the UTF-8 article), and trail units have the range 80–BF. The lead unit also tells how many trail units follow: one after C2–DF, two after E0–EF and three after F0–F4.[lower-alpha 3]

UTF-16 was devised to break free of the 65,536-character limit of the original Unicode (1.x) without breaking compatibility with the 16-bit encoding. In UTF-16, singletons have the range 0000–D7FF (55,296 code points) and E000–FFFF (8192 code points, 63,488 in total), lead units the range D800–DBFF (1024 code points) and trail units the range DC00–DFFF (1024 code points, 2048 in total). The lead and trail units, called high surrogates and low surrogates, respectively, in Unicode terminology, map 1024×1024 or 1,048,576 supplementary characters, making 1,112,064 (63,488 BMP code points + 1,048,576 code points represented by high and low surrogate pairs) encodable code points, or scalar values in Unicode parlance (surrogates are not encodable).

## See also

* wchar t wide characters
* Lotus Multi-Byte Character Set (LMBCS)
* Triple-Byte Character Set (TBCS)
* Double-byte character set (DBCS)
* Single-Byte Character Set (SBCS)

## Notes

1. ↑ The concept long precedes the advent of the electronic computer, however, as seen with Morse code.
2. ↑ As a real-life example of this, UTF-16, which represents the most common characters in exactly the manner just described (and uses pairs of 16-bit code units for less-common characters) never gained traction as an encoding for text intended for interchange due to its incompatibility with the ubiquitous 7-/8-bit ASCII encoding, with its intended role instead being taken by UTF-8, which does preserve ASCII compatibility.
3. ↑ In the original version of UTF-8, from its 1992 publication until its code space was restricted to that of UTF-16 in 2003, the range of lead units encoding three-unit trailing sequences was larger (F0–F7); additionally, the lead units F8–FB were followed by four trail units, and FC–FD by five. FE–FF were never valid lead or trail units in any version of UTF-8.

## References

1. ↑ Template:Cite RFC

* v
* t
* e

Character encodings

Early telecommunications|

* ASCII
* ISO/IEC 646
* ISO/IEC 6937 / ITU T.51
* ITU T.61
* BCDIC
* Baudot code
* Morse code
* Telegraph code
* Wabun code
* Special telegraphy codes
* Non-Latin
* Chinese
* Cyrillic
* Needle telegraph codes

ISO/IEC 8859|

* Approved
* -1
* -2
* -3
* -4
* -5
* -6
* -7
* -8
* -9
* -10
* -11
* -13
* -14
* -15
* -16
* Abandoned
* -12
* Adaptations
* ISO-IR-182
* ISO-IR-200
* ISO-IR-201
* Proposed but not approved
* ISO-IR-111
* ISO-IR-197
* French/Dutch/Turkish draft

Bibliographic use|

* ANSEL
* ISO 5426 / 5426-2 / 5427 / 5428 / 6438 / 6861 / 6862 / 10585 / 10586 / 10754 / 11822
* MARC-8

National standards|

* ArmSCII
* BraSCII
* CNS 11643
* ELOT 927
* GOST 10859
* GB 18030
* HKSCS
* I.S. 434
* ISCII
* JIS X 0201
* JIS X 0208
* JIS X 0212
* JIS X 0213
* KOI-7
* KPS 9566
* KS X 1001
* PASCII
* SI 960
* TIS-620
* TSCII
* VISCII
* VSCII
* YUSCII

ISO/IEC 2022|

* 7-bit
* CN
* CN-EXT
* JP
* JP-EXT
* JP-1
* JP-2
* JP-3
* KR
* ISO/IEC 4873
* ISO/IEC 8859
* ISO/IEC 10367
* Extended Unix Code / EUC
* CN
* KR
* JP
* TW
* CCCII

MacOS code pages
("scripts")|

* Armenian
* Arabic
* Barents Cyrillic
* Celtic
* CentEuro
* ChineseSimp / EUC-CN
* ChineseTrad / Big5
* Croatian
* Cyrillic
* Devanagari
* Dingbats
* Farsi (Persian)
* Gaelic
* Georgian
* Greek
* Gujarati
* Gurmukhi
* Hebrew
* Iceland
* Inuit
* Japanese / ShiftJIS
* Keyboard
* Korean / EUC-KR
* Latin (Kermit)
* Maltese/Esperanto
* Ogham / I.S. 434
* Roman
* Romanian
* Sámi
* Symbol
* Thai / TIS-620
* Turkish
* Turkic Cyrillic
* Ukrainian
* VT100

DOS code pages|

* 100
* 111
* 112
* 113
* 151
* 152
* 161
* 162
* 163
* 164
* 165
* 166
* 210
* 220
* 301
* 437
* 449
* 489
* 620
* 667
* 668
* 707
* 708
* 709
* 710
* 711
* 714
* 715
* 720
* 721
* 737
* 768
* 770
* 771
* 772
* 773
* 774
* 775
* 776
* 777
* 778
* 790
* 850
* 851
* 852
* 853
* 854
* 855/872
* 856
* 857
* 858
* 859
* 860
* 861
* 862
* 863
* 864/17248
* 865
* 866/808
* 867
* 868
* 869
* 874/1161/1162
* 876
* 877
* 878
* 881
* 882
* 883
* 884
* 885
* 891
* 895
* 896
* 897
* 898
* 899
* 900
* 903
* 904
* 906
* 907
* 909
* 910
* 911
* 926
* 927
* 928
* 929
* 932
* 934
* 936
* 938
* 941
* 942
* 943
* 944
* 946
* 947
* 948
* 949
* 950/1370
* 951
* 966
* 991
* 1034
* 1039
* 1040
* 1041
* 1042
* 1043
* 1044
* 1046
* 1086
* 1088
* 1092
* 1093
* 1098
* 1108
* 1109
* 1114
* 1115
* 1116
* 1117
* 1118
* 1119
* 1125/848
* 1126
* 1127
* 1131/849
* 1139
* 1167
* 1168
* 1300
* 1351
* 1361
* 1362
* 1363
* 1372
* 1373
* 1374
* 1375
* 1380
* 1381
* 1385
* 1386
* 1391
* 1392
* 1393
* 1394
* 57781
* 58152
* 58210
* 58335
* 59234
* 59829
* 60258
* 60853
* 61282
* 62306
* CS Indic
* CSX Indic
* CSX+ Indic
* CWI-2
* Iran System
* Kamenický
* KOI8
* Mazovia
* MIK

IBM AIX code pages|

* 367
* 371
* 806
* 813
* 819
* 895
* 896
* 912
* 913
* 914
* 915
* 916
* 919
* 920
* 921/901
* 922/902
* 923
* 952
* 953
* 954
* 955
* 956
* 957
* 958
* 959
* 960
* 961
* 963
* 964
* 965
* 970
* 971
* 1004
* 1006
* 1008
* 1009
* 1010
* 1011
* 1012
* 1013
* 1014
* 1015
* 1016
* 1017
* 1018
* 1019
* 1029
* 1036
* 1089
* 1111
* 1124
* 1129/1163
* 1133
* 1350
* 1382
* 1383

IBM Apple MacIntosh
emulations|

* 1275
* 1280
* 1281
* 1282
* 1283
* 1284
* 1285
* 1286

IBM Adobe emulations|

* 1038
* 1276
* 1277

IBM DEC emulations|

* 1020
* 1021
* 1023
* 1090
* 1100
* 1101
* 1102
* 1103
* 1104
* 1105
* 1106
* 1107
* 1287
* 1288

IBM HP emulations|

* 1050
* 1051
* 1052
* 1053
* 1054
* 1055
* 1056
* 1057
* 1058

Windows code pages|

* CER-GS
* 874/1162 (TIS-620)
* 932/943 (Shift JIS)
* 936/1386 (GBK)
* 950/1370 (Big5)
* 949/1363 (EUC-KR)
* 1169
* 1174
* Extended Latin-8
* 1200 (UTF-16LE)
* 1201 (UTF-16BE)
* 1250
* 1251
* 1252
* 1253
* 1254
* 1255
* 1256
* 1257
* 1258
* 1261
* 1270
* 54936 (GB18030)
* 65001 (UTF-8)

EBCDIC EBCDIC code pages|

* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
* 24
* 25
* 26
* 27
* 28
* 29
* 30
* 31
* 32
* 33
* 34
* 35
* 36
* 37/1140
* 37-2
* 38
* 39
* 40
* 251
* 252
* 254
* 256
* 257
* 258
* 259
* 260
* 264
* 273/1141
* 274
* 275
* 276
* 277/1142
* 278/1143
* 279
* 280/1144
* 281
* 282
* 283
* 284/1145
* 285/1146
* 286
* 287
* 288
* 289
* 290
* 293
* 297/1147
* 298
* 300
* 310
* 320
* 321
* 322
* 330
* 351
* 352
* 353
* 355
* 357
* 358
* 359
* 360
* 361
* 363
* 382
* 383
* 384
* 385
* 386
* 387
* 388
* 389
* 390
* 391
* 392
* 393
* 394
* 395
* 410
* 420/16804
* 421
* 423
* 424/8616/12712
* 425
* 435
* 500/1148
* 803
* 829
* 833
* 834
* 835
* 836
* 837
* 838/1160
* 839
* 870/1110/1153
* 871/1149
* 875/4971/9067
* 880
* 881
* 882
* 883
* 884
* 885
* 886
* 887
* 888
* 889
* 890
* 892
* 893
* 905
* 918
* 924
* 930/1390
* 931
* 933/1364
* 935/1388
* 937/1371
* 939/1399
* 1001
* 1002
* 1003
* 1005
* 1007
* 1024
* 1025/1154
* 1026/1155
* 1027
* 1028
* 1030
* 1031
* 1032
* 1033
* 1037
* 1047
* 1068
* 1069
* 1070
* 1071
* 1073
* 1074
* 1075
* 1076
* 1077
* 1078
* 1079
* 1080
* 1081
* 1082
* 1083
* 1084
* 1085
* 1087
* 1091
* 1097
* 1112/1156
* 1113
* 1122/1157
* 1123/1158
* 1130/1164
* 1132
* 1136
* 1137
* 1150
* 1151
* 1152
* 1159
* 1165
* 1166
* 1278
* 1279
* 1303
* 1364
* 1376
* 1377
* JEF
* KEIS

DEC terminals (VTx)|

* Multinational (MCS)
* National Replacement (NRCS)
* French Canadian
* Swiss
* Spanish
* United Kingdom
* Dutch
* Finnish
* French
* Norwegian and Danish
* Swedish
* Norwegian and Danish (alternative)
* 8-bit Greek
* 8-bit Turkish
* 7-bit Hebrew
* 8-bit Hebrew
* Special Graphics
* Technical (TCS)

Platform specific|

* Acorn
* Adobe Standard
* Adobe Latin 1
* Amstrad CPC
* Apple I
* Apple II
* Apple III
* ATASCII
* Atari ST
* BICS
* Casio calculators
* CDC
* Compucolor II
* DEC Radix-50
* DEC MCS/NRCS
* DG International
* ELWRO-Junior
* FIELDATA
* GEM
* GEOS
* GSM 03.38
* HP Roman Extension
* HP Roman-8
* HP Roman-9
* HP FOCAL
* HP RPL
* LICS
* LMBCS
* Mattel Aquarius
* Minitel
* MSX
* NEC APC
* NeXT
* OricSCII
* PCW
* PETSCII
* Sega SC-3000
* Sharp calculators
* Sharp MZ
* Sinclair QL
* Teletext
* TI calculators
* TRS-80
* Ventura International
* Ventura Symbol
* Videotex
* WISCII
* XCCS
* ZX80
* ZX81
* ZX Spectrum

Unicode / ISO/IEC 10646|

* UTF-1
* UTF-7
* UTF-8
* UTF-16 (UTF-16LE/UTF-16BE) / UCS-2
* UTF-32 (UTF-32LE/UTF-32BE) / UCS-4
* UTF-EBCDIC
* GB 18030
* BOCU-1
* CESU-8
* SCSU

TeX typesetting system|

* Cork
* LGR
* LY1
* OML
* OMS
* OMX
* OT1
* OT2
* OT3
* OT4
* T2A
* T2B
* T2C
* T2D
* T3
* T4
* T5
* TS1
* TS3
* U
* X2

Miscellaneous code pages|

* ABICOMP
* APL
* 293
* 310 (Graphic Escape)
* 351 (GDDM)
* 907 (OEM)
* ISO-IR-68
* ARIB STD-B24
* HZ
* IEC-P27-1
* INIS
* 7-bit
* 8-bit
* Cyrillic
* ISO-IR-169
* ISO 2033
* Johab
* SEASCII
* Stanford/ITS
* TACE16
* TRON
* UTF-5
* UTF-6
* WTF-8

Related topics|

* Code page
* Control character (C0 C1)
* CCSID
* Character encodings in HTML
* Charset detection
* Han unification
* Hardware
* ISO 6429/IEC 6429/ANSI X3.64
* Mojibake

Character sets

0.00

(0 votes)

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Variable-width_encoding&oldid=3907320"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template