Introduction
UTF-32BE stores each Unicode character as one 32-bit number, its code point, written
high byte first (big-endian). Every character takes exactly four bytes, so the
hundredth character of a file is always at byte 396, or 400 after a byte order mark.
Read in a hex dump, each unit shows its code point directly: 00 00 20 AC
is U+20AC. It is the simplest Unicode encoding to work with, and the largest: ASCII
text takes four times the space it takes in UTF-8. UTF-32 is used inside programs far
more than in files, and UTF-32BE files are rarer still; none of the text files examined
for this site used it.
UTF-32 was defined in Unicode Standard Annex #19, and has been part of the core
Unicode Standard since version
4.0 (2003). It is the part of ISO 10646’s UCS-4 that Unicode uses, the code points
from 0 to 10FFFF; UCS-4 itself is a 31-bit form that reached
7FFFFFFF. Browsers do not decode it: it is not in the
WHATWG Encoding Standard, whose list
of encodings is closed. The explorer decodes it itself.
A UTF-32BE text file has no header and no length fields: an optional byte order mark, then 4-byte units to the end of the file. The same text in UTF-32LE has every unit’s bytes reversed, and in UTF-16BE or UTF-8 it has different bytes altogether, so each is a format of its own.
A file dropped on any page of this site opens in the explorer, which shows its structure (the byte order mark, each line, and for a line beyond ASCII each character with its bytes) and a preview of the text.
Structure
The file has two parts. Its length is a whole number of 4-byte units.
0Byte order mark00 00 FE FF, when present0 or 4 bytes0 or 4Lines characters of four bytes each, each line followed by its line endingvaries
Byte order mark
The character U+FEFF, ZERO WIDTH NO-BREAK SPACE, written at the very start of a file,
is the byte order mark (BOM). As a 32-bit number high byte first, it is
00 00 FE FF. It is not part of the text, and a reader drops it. Unlike
UTF-32LE’s mark, it is hard to mistake for UTF-16’s: a UTF-16 file starts with two zero
bytes only if its text starts with U+0000.
The Unicode Standard and the
FAQ separate three things.
UTF-32 is the scheme whose byte order is named by a mark at the
start, and an unmarked “UTF-32” is read as big-endian. UTF-32LE and
UTF-32BE are the schemes where the byte order is fixed by the
label: a BOM is neither necessary nor permitted, and a U+FEFF at the start is then
an ordinary character, a ZERO WIDTH NO-BREAK SPACE. A file has no label to read, so
the explorer goes by the bytes: 00 00 FE FF is the UTF-32 scheme,
big-endian, and the Text section says so; no mark is UTF-32BE only when its units read
as code points in this order.
| First bytes | Encoding |
|---|---|
00 00 FE FF | UTF-32BE (this format) |
FF FE 00 00 | UTF-32LE, or UTF-16LE then U+0000 |
FE FF | UTF-16BE |
FF FE | UTF-16LE |
EF BB BF | UTF-8 |
A U+FEFF further on in the text is the character ZERO WIDTH NO-BREAK SPACE, as the FAQ says, not a mark, though U+2060 WORD JOINER is the character to use for that today. It is usually a mark left behind where two files were joined, so the explorer points it out.
Encoding
Each character is one 32-bit unsigned number, the code point itself, written in four bytes from the highest to the lowest. There is nothing to compute. A unit is valid when its value is a Unicode scalar value:
| Value | Meaning |
|---|---|
00000000 to 0000D7FF | a character |
0000D800 to 0000DFFF | a surrogate: not a character, not allowed |
0000E000 to 0010FFFF | a character |
00110000 and above | beyond Unicode: not allowed |
So the first byte of every unit is 00, and the second is
00 to 10.
Worked examples
| Character | Code point | UTF-32BE |
|---|---|---|
| A | U+0041 | 00 00 00 41 |
| é | U+00E9 | 00 00 00 E9 |
| € | U+20AC | 00 00 20 AC |
| 中 | U+4E2D | 00 00 4E 2D |
| 😀 | U+1F600 | 00 01 F6 00 |
This 44-byte file holds two lines, “Café €4” and “😀”, each ending in LF, after a byte order mark. The mark and the character above U+FFFF are marked:
00000000 00 00 FE FF 00 00 00 43 00 00 00 61 00 00 00 66 .......C...a...f
00000010 00 00 00 E9 00 00 00 20 00 00 20 AC 00 00 00 34 ....... .. ....4
00000020 00 00 00 0A 00 01 F6 00 00 00 00 0A ............
Properties
- Every character is the same size, so the nth character is found by multiplying, with no scanning.
- At least one byte in four, and in Latin text three in four, is zero. Programs that treat a zero byte as the end of a string cannot handle it.
- A reader must start on a multiple of four. One byte lost or added shifts every character after it, and the shifted units are then mostly invalid, which makes the damage easy to see.
Control codes and special characters
Each of these occupies a code point but draws no glyph, so the explorer names it in its character list. U+0000 to U+001F are the C0 control codes of ASCII, U+0080 to U+009F the C1 control codes of ISO 6429.
| Code point | Abbr. | Name | Function |
|---|---|---|---|
| U+0000 | NUL | NULL | fills time or space; means nothing in text |
| U+0001 | SOH | START OF HEADING | starts the heading of a message |
| U+0002 | STX | START OF TEXT | ends the heading and starts the body |
| U+0003 | ETX | END OF TEXT | ends the body; Ctrl-C |
| U+0004 | EOT | END OF TRANSMISSION | ends a transmission; Ctrl-D |
| U+0005 | ENQ | ENQUIRY | asks the other end to respond |
| U+0006 | ACK | ACKNOWLEDGE | positive response to an enquiry |
| U+0007 | BEL | BELL | makes a sound or a flash |
| U+0008 | BS | BACKSPACE | moves back one position |
| U+0009 | HT | HORIZONTAL TABULATION | moves to the next tab stop: the tab character |
| U+000A | LF | LINE FEED | moves down one line; ends a line on Unix |
| U+000B | VT | LINE TABULATION | vertical tab: a mandatory line break in UAX #14 |
| U+000C | FF | FORM FEED | starts a new page; a mandatory line break in UAX #14 |
| U+000D | CR | CARRIAGE RETURN | moves to the start of the line; ends a line on the classic Mac OS |
| U+000E | SO | SHIFT OUT | switches to an alternative character set |
| U+000F | SI | SHIFT IN | switches back to the standard character set |
| U+0010 | DLE | DATA LINK ESCAPE | changes the meaning of the next few characters |
| U+0011 | DC1 | DEVICE CONTROL ONE | device control; XON, resume output |
| U+0012 | DC2 | DEVICE CONTROL TWO | device control |
| U+0013 | DC3 | DEVICE CONTROL THREE | device control; XOFF, pause output |
| U+0014 | DC4 | DEVICE CONTROL FOUR | device control |
| U+0015 | NAK | NEGATIVE ACKNOWLEDGE | negative response to an enquiry |
| U+0016 | SYN | SYNCHRONOUS IDLE | keeps a synchronous link in step |
| U+0017 | ETB | END OF TRANSMISSION BLOCK | ends a block of data |
| U+0018 | CAN | CANCEL | says the data before it should be ignored |
| U+0019 | EM | END OF MEDIUM | marks the end of a recording medium |
| U+001A | SUB | SUBSTITUTE | stands for an invalid character; Ctrl-Z, end of a DOS text file |
| U+001B | ESC | ESCAPE | starts an escape sequence |
| U+001C | FS | INFORMATION SEPARATOR FOUR | file separator |
| U+001D | GS | INFORMATION SEPARATOR THREE | group separator |
| U+001E | RS | INFORMATION SEPARATOR TWO | record separator |
| U+001F | US | INFORMATION SEPARATOR ONE | unit separator |
| U+007F | DEL | DELETE | marks a position as erased |
| U+0080 | PAD | PADDING CHARACTER | a Unicode name alias, not part of ISO 6429 |
| U+0081 | HOP | HIGH OCTET PRESET | a Unicode name alias, not part of ISO 6429 |
| U+0082 | BPH | BREAK PERMITTED HERE | marks a place where a line may be broken |
| U+0083 | NBH | NO BREAK HERE | marks a place where a line must not be broken |
| U+0084 | IND | INDEX | moves down one line; withdrawn from ISO 6429 |
| U+0085 | NEL | NEXT LINE | moves to the start of the next line; the line end of EBCDIC systems |
| U+0086 | SSA | START OF SELECTED AREA | starts a selected area of a page |
| U+0087 | ESA | END OF SELECTED AREA | ends a selected area of a page |
| U+0088 | HTS | CHARACTER TABULATION SET | sets a horizontal tab stop here |
| U+0089 | HTJ | CHARACTER TABULATION WITH JUSTIFICATION | tab with the text before it justified |
| U+008A | VTS | LINE TABULATION SET | sets a vertical tab stop here |
| U+008B | PLD | PARTIAL LINE FORWARD | moves down part of a line, for subscripts |
| U+008C | PLU | PARTIAL LINE BACKWARD | moves up part of a line, for superscripts |
| U+008D | RI | REVERSE LINE FEED | moves up one line |
| U+008E | SS2 | SINGLE-SHIFT TWO | the next character comes from code set G2 |
| U+008F | SS3 | SINGLE-SHIFT THREE | the next character comes from code set G3 |
| U+0090 | DCS | DEVICE CONTROL STRING | starts a device control string |
| U+0091 | PU1 | PRIVATE USE ONE | reserved for private use |
| U+0092 | PU2 | PRIVATE USE TWO | reserved for private use |
| U+0093 | STS | SET TRANSMIT STATE | sets the transmit state |
| U+0094 | CCH | CANCEL CHARACTER | erases the character before it |
| U+0095 | MW | MESSAGE WAITING | says a message is waiting |
| U+0096 | SPA | START OF PROTECTED AREA | starts a protected area of a page |
| U+0097 | EPA | END OF PROTECTED AREA | ends a protected area of a page |
| U+0098 | SOS | START OF STRING | starts a control string |
| U+0099 | SGCI | SINGLE GRAPHIC CHARACTER INTRODUCER | a Unicode name alias, not part of ISO 6429 |
| U+009A | SCI | SINGLE CHARACTER INTRODUCER | the next character is a control function |
| U+009B | CSI | CONTROL SEQUENCE INTRODUCER | starts a control sequence |
| U+009C | ST | STRING TERMINATOR | ends a control string |
| U+009D | OSC | OPERATING SYSTEM COMMAND | starts an operating system command |
| U+009E | PM | PRIVACY MESSAGE | starts a privacy message |
| U+009F | APC | APPLICATION PROGRAM COMMAND | starts an application program command |
The explorer names every other assigned code point, such as U+00E9 LATIN SMALL LETTER E WITH ACUTE, from the Unicode Character Database’s UnicodeData.txt, version 18.0.0, copied unchanged into the site (explorer/formats/txt/data/) and read the first time a character needs it; the file is Unicode, Inc.’s data under the Unicode Terms of Use. Names of CJK ideographs and similar ranges are made from the ranges that file gives, and Hangul syllables by the algorithm of the Unicode Standard. U+2F800 to U+2FA1D are CJK compatibility ideographs. A code point the file does not have is not assigned and gets no name. The category comes from the same file and the script from the browser’s own Unicode data. If the file cannot be read, only the control, blank, format and Hangul names are given.
The Unicode Standard sets aside 66 noncharacters: U+FDD0 to U+FDEF, and the last two code points of each of the seventeen planes (U+FFFE, U+FFFF, U+1FFFE, U+1FFFF and so on up to U+10FFFE, U+10FFFF). They are valid in UTF-32, as the FAQ says, but they are meant for a program’s internal use and should not be interchanged in text. The explorer names each noncharacter and reports the count.
Lines
Limits of the viewer. The Text tab shows a text of up to 16 MB (16,777,216 bytes) at once. A longer file is shown in windows of about 1 MB: each window ends at a line ending, or, inside a line longer than a window, between two 4-byte units. The bar above the text has First, Previous, Next, Last and Go to line, the windows follow one another with no gap, and so every byte of the file can be read there. A row of the Lines table shows the first 1,000 characters of its line, then “…”; the rest of the line is in the Text tab and in the tree, which holds every line and, inside each line, every character, however long. The counts cover the whole file.
Options. Leading U+FEFF: the bytes 00 00 FE FF are read as the byte order mark, the default (Unicode Standard section 3.10), or as the ordinary character U+FEFF, which is what a text labelled “UTF-32BE” means, since that name has no mark. UTF-32 with bad units: when more than one unit in ten after the mark is not a Unicode scalar value (a surrogate or above U+10FFFF, section 3.9.1) the default does not read the file as UTF-32; the other choice reads it as UTF-32 and reports each bad unit.
A line is the characters up to a line
ending. The explorer counts one line for each line ending, plus one for any text
after the last, so a␊b␊ and a␊b are both two lines. Lines
are numbered from 1, as editors number them.
POSIX defines a line as ending in a newline, so a last line with no line ending is, strictly, incomplete. It is common and harmless, and the explorer gives it as a note, not a problem.
Characters are counted as units, one per character, not counting the line endings.
The longest line is measured in characters. Tabs (00 00 00 09), form
feeds (00 00 00 0C, page breaks) and vertical tabs
(00 00 00 0B) are counted and not reported. Every line can be opened into
its characters, however long it is and even when it is all ASCII.
Line endings
Each line-ending character is one unit, four bytes, high byte first. Unicode’s newline guidelines (chapter 5 of the Standard) list CR, LF, CR LF and NEL as newline functions, and LS and PS as separators; the explorer ends a line at any of the six:
| Name | Code point | UTF-32BE bytes | Where it is used |
|---|---|---|---|
| LF (line feed) | U+000A | 00 00 00 0A | Unix, Linux, macOS |
| CR LF | U+000D U+000A | 00 00 00 0D 00 00 00 0A | Windows, MS-DOS, Internet protocols |
| CR (carriage return) | U+000D | 00 00 00 0D | classic Mac OS (up to 9) |
| NEL (next line) | U+0085 | 00 00 00 85 | EBCDIC systems’ NL, mapped to Unicode |
| LS (line separator) | U+2028 | 00 00 20 28 | Unicode only, rare |
| PS (paragraph separator) | U+2029 | 00 00 20 29 | Unicode only, rare |
A file with more than one kind of ending is reported as having mixed line endings, with the first line that differs from the commonest kind. The vertical tab and the form feed do not end lines.
End of the file
The text stops at the end of the file. There is no end-of-file mark in UTF-32
files: the Ctrl-Z of MS-DOS belongs to byte-oriented text. Zero units at the end
(00 00 00 00) are NUL characters, and the explorer reports them as
such.
When the file’s length is not a multiple of four, the last one to three bytes are part of a unit. The explorer reports them as a character cut short by the end of the file.
Problems
A unit is wrong when its value is not a Unicode scalar value:
- Above
10FFFF, such as00 11 00 00(110000). This is an invalid byte sequence. It is also what text in another encoding looks like when read as UTF-32. - A surrogate,
D800toDFFF, such as00 00 D8 3D. Surrogates belong to UTF-16 only; one here is usually UTF-16 converted unit by unit without joining the pairs. The explorer reports it as an unpaired surrogate. - A unit cut short by the end of the file.
A strict decoder stops with an error; a lenient one puts U+FFFD, the replacement character �, in place of each bad unit. The explorer shows the bad unit’s bytes in the tree, reports it, and shows U+FFFD for it in the text preview.
| Problem | Meaning |
|---|---|
| invalid byte sequence | a unit above 10FFFF |
| unpaired surrogate | a unit from D800 to DFFF |
| NUL character | U+0000 in the text |
| control character | a C0 control other than tab, LF, form feed and CR; DEL; or a C1 control, U+0080 to U+009F, other than NEL |
| U+FEFF inside the text | a zero width no-break space after the start, usually a leftover byte order mark |
| noncharacter | one of the 66 noncharacters: valid, but not meant for interchange |
| character cut short by the end of the file | one to three bytes left over |
| mixed line endings | more than one kind of line ending |
Telling it apart
UTF-32 is the easiest Unicode encoding to recognise without a byte order mark, because almost no other data passes its test. The explorer’s parser for this format checks:
- With the mark
00 00 FE FF: the units after it, up to 64 KB, are read. If more than one in ten are not code points, the file is turned down. - Without it: every 4-byte unit of the first 64 KB, read high byte
first, must be a code point (at most
10FFFF, not a surrogate). A single bad unit turns the file down. Text in UTF-16 or in an 8-bit encoding never passes: its bytes make values far above10FFFF. Nor does UTF-32LE: read high byte first, its units are far above10FFFFtoo. - The units must not look binary: NUL in more than one character in a hundred, or other control characters in more than one in ten, turns the file down.
The text formats are tried UTF-8 first, then UTF-32LE, then this one, then the two UTF-16 formats.
Variants
- UTF-8 text – one to four bytes a character, ASCII unchanged
- UTF-16LE text – two or four bytes a character, low byte first
- UTF-16BE text – two or four bytes a character, high byte first
- UTF-32LE text – four bytes a character, low byte first
- UTF-32BE text – four bytes a character, high byte first
- Legacy code page text – a pre-Unicode code page that the file does not name
- UTF-7 text – Unicode as pure ASCII, with Base64 runs
- ISO-2022 and HZ text – 7-bit Japanese, Korean and Chinese with escape sequences
- GB18030 text – China’s national encoding, one, two or four bytes a character
- EBCDIC text – IBM mainframe text, not based on ASCII
- SCSU text – Unicode compressed with windows and tags
- BOCU-1 text – Unicode as differences between code points
- UTF-1 text – the withdrawn ISO 10646 transformation
- UTF-EBCDIC text – UTF-8 for EBCDIC systems
Links
Software
Developers
- ICU – conversion between encodings, UTF-32 among them (C, C++, Java)
- GNU libiconv – the iconv conversion library (C)
Reference
- The Unicode Standard – the encoding forms, UTF-32 among them (chapter 3), and newline guidelines (chapter 5)
- Unicode FAQ: UTF-8, UTF-16, UTF-32 and BOM – the Unicode Consortium’s answers on UTF-32 and byte order marks
- UAX #19 – the annex that first defined UTF-32, now superseded by the core standard