What is the size of a Unicode character in the Windows Operating System?

2012

What is the size of a Unicode character in the Windows Operating System?

Answer: B. 16-BitsConcept — Unicode itself only assigns each character a number — a code point in the range U+0000 to U+10FFFF; it does not by itself fix how many bits a…

  1. A.

    8-Bits

  2. B.

    16-Bits

  3. C.

    32-Bits

  4. D.

    64-Bits

Attempted by 7 students.

Show answer & explanation

Correct answer: B

Concept — Unicode itself only assigns each character a number — a code point in the range U+0000 to U+10FFFF; it does not by itself fix how many bits a character occupies in storage. That width comes from the encoding form a platform adopts for its native text: a UTF-8 code unit is 8 bits wide, a UTF-16 code unit is 16 bits wide, and a UTF-32 code unit is 32 bits wide. So asking for the size of a Unicode character on a platform is really asking for the width of one code unit of that platform's native Unicode encoding form.

Application — Windows (the NT family) represents text natively in UTF-16. Its wide-character type WCHAR is defined as wchar_t, and on Windows wchar_t is a 16-bit type with the same size and representation as unsigned short — two bytes wide. The wide "W" entry points of the Win32 API, such as CreateFileW and MessageBoxW, accordingly take LPWSTR strings built from these two-byte units, and NTFS file names, registry keys and kernel object names are stored in the same units. One such unit is 16 bits, which is therefore the size of a Unicode character in Windows.

Cross-check — The other widths on offer are the code-unit widths of the remaining encoding forms, or the widths of ordinary numeric types:

Encoding form

Code-unit width

Typical C/C++ type

UTF-8

8 bits

char

UTF-16

16 bits

wchar_t on Windows, char16_t

UTF-32

32 bits

char32_t, wchar_t on Linux

no Unicode encoding form

64 bits

long long, double

Two details are worth keeping straight. First, 16 bits is the width of a code unit, not of every character: one unit covers the 216 = 65,536 code positions of the Basic Multilingual Plane, of which 2,048 are surrogate code points reserved for reaching the higher planes, so a code point above U+FFFF — an emoji or a rare CJK ideograph — is stored as a surrogate pair of two such units. Second, the older "A" entry points of the Win32 API, such as CreateFileA, are not Unicode at all: they take 8-bit char strings interpreted through the process code page, and Windows converts them to UTF-16 internally.

Result — Windows stores and processes Unicode text as UTF-16, whose code unit — the WCHAR — is two bytes, so the size of a Unicode character in Windows is 16 bits.

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…