# MARC-8

The MARC-8 charset is a MARC standard used in MARC-21 library records. The MARC formats are standards for the representation and communication of bibliographic and related information in machine-readable form, and they are frequently used in library database systems. The character encoding now known as MARC-8 was introduced in 1968 as part of the MARC format. Originally based on the Latin alphabet, from 1979 to 1983 the JACKPHY initiative expanded the repertoire to include Japanese, Arabic, Chinese, and Hebrew characters (among others), with the later addition of Cyrillic and Greek scripts. If a character is not representable in MARC-8 of a MARC-21 record, then UTF-8 must be used instead. UTF-8 has support for many more characters than MARC-8, which is rarely used outside library data.

## Technical details

MARC-8 uses a variant of the ISO-2022 encoding. It uses escape characters to represent characters beyond the 7-bit ASCII range of characters.
It generally uses the same logical BiDi ordering as Unicode.
The combining characters and base characters are in a different order than used in Unicode. The following are some examples. The combining characters are not always stored in reverse order as Unicode normalization. The MARC-21 standard describes the MARC-8 Unicode conversion issues in more detail.
| Displayed Character | Unicode NFD | MARC-8 |
| á | a ́ | ́ a |
| ậ | a ̣ ̂ | ̂ ̣ a |

### Code structure

The ISO/IEC 2022 coding specifies a two-layer mapping between character codes and displayed characters. In MARC-8, character codes from the 7-bit ASCII graphic range (0x20–0x7F) are referred to as "G0" codes, while codes from the "high ASCII" range (0xA0–0xFF) are referred to as the "G1" codes. Graphic character sets are designated and invoked by means of a multiple byte escape sequence consisting of the escape character, an Intermediate character sequence, and a Final character in the form ESC I F.
The following table shows the intermediate byte after the ESC byte (hexadecimal 1B), and the corresponding ASCII characters.
Intermediate Bytes :
| | G0 set | G0 set | G0 set | G0 set | G1 set | G1 set | G1 set | G1 set |
| | SBCS | | MBCS | | SBCS | | MBCS | |
| Normal ISO-2022 | 28 | ( | 24 | $ | 29 | ) | 24 29 | $) |
| Alternate ISO-2022 (additional 63+16 sets) | 2C | , | 24 2C | $, | 2D | - | 24 2D | $- |
The following table shows the final bytes in hexadecimal and the corresponding ASCII characters after the intermediate bytes.
Final Bytes :
| Bytes | Characters | Name | Type | Comment |
| 31 | 1 | Chinese, Japanese, Korean (EACC) | MBCS | |
| 32 | 2 | Basic Hebrew | SBCS | |
| 33 | 3 | Basic Arabic | SBCS | |
| 34 | 4 | Extended Arabic | SBCS | |
| 42 | B | Basic Latin (ASCII) | SBCS | |
| 21 45 | !E | Extended Latin (ANSEL) | SBCS | The 21(hex) technically is a second byte of the Intermediate segment of this escape sequence. |
| 4E | N | Basic Cyrillic | SBCS | |
| 51 | Q | Extended Cyrillic | SBCS | |
| 53 | S | Basic Greek (ISO 5428) | SBCS | |
The EACC is the only multibyte encoding of MARC-8, it encodes each CJK character in three ASCII bytes.
For example, to encode the U+4EBA CJK character (人) you will need the following bytes
The \x1B\x24\x31 switches to EACC/CJK, and the \x21\x30\x64 corresponds to the U+4EBA.

### Custom set extension

In addition to the ISO-2022 character sets, the following custom sets are available too. The byte designation follows the escape byte (hexadecimal 1B). There is no intermediate byte.
Final Bytes :
| Bytes | Characters | Name | Type | Comment |
| 62 | b | Subscript set | SBCS | |
| 67 | g | Greek Symbol set | SBCS | The alpha, beta, gamma characters normally do not round trip map to Unicode. |
| 70 | p | Superscript set | SBCS | |
| 73 | s | Basic Latin (ASCII) | SBCS | |

### C0 control codes

MARC 21 uses GS (0x1D) as a record terminator, RS (0x1E) as a field terminator and US (0x1F) as a subfield delimiter.

### C1 control codes

The following alternative C1 control code set is defined for bibliographic applications such as library systems. It is mostly concerned with string collation, and with markup of bibliographic fields. Slightly different variants are defined in the German standard DIN 31626 (published in 1978 and since withdrawn) and the ISO standard ISO 6630, the latter of which has also been adopted in Germany as DIN ISO 6630. Where these differ is noted in the table below where applicable. MARC-8 uses the coding of NSB and NSE from this set, and adds some additional format effectors in locations not used by the ISO version; however, MARC 21 uses this control set only in MARC-8 records, not in Unicode-format records.
If using the ISO/IEC 2022 extension mechanism, the DIN 31626 set is designated as the active C1 control character set with the sequence 0x1B 0x22 0x45 (ESC " E), and the ISO 6630 / DIN ISO 6630 set is designated with the sequence 0x1B 0x22 0x42 (ESC " B). The 1985 expansion of the ISO 6630 set can also be explicitly specified by using the sequence 0x1B 0x26 0x40 0x1B 0x22 0x42 (ESC & @ ESC " B).
| Esc+ | Dec | Hex | Acro | Name | Description |
| G | 135 | 87 | CUS | Close-Up for Sorting | (DIN 31626, ISO 6630) Declares that two successive character sequences separated by a space or separator should be treated as one word for collation purposes. |
| H | 136 | 88 | NSB | Non-Sorting Characters Begin | (DIN 31626, ISO 6630, MARC 21) Marks the start of a sequence of characters to be ignored for collation purposes. MARC 21 uses this character in MARC-8 records, but uses 0x98 (SOS) in Unicode records for the same purpose. |
| I | 137 | 89 | NSE | Non-Sorting Characters End | (DIN 31626, ISO 6630, MARC 21) Marks the end of a sequence of characters to be ignored for collation purposes. MARC 21 uses this character in MARC-8 records, but uses 0x9C (ST) in Unicode records for the same purpose. |
| J | 138 | 8A | FIL | Filler Character | (DIN 31626) Substitutes for a mandatory alphanumeric character in a field. |
| K | 139 | 8B | TCI | Tag in Context Indicator | (DIN 31626) Within a bibliographic field, used to refer to data in another bibliographic field by its tag number. |
| K | 139 | 8B | PLD | Partial Line Down | (ISO 6630) Not in the original edition of ISO 6630. In the 1985 edition of ISO 6630, used for Partial Line Down (see PLD). |
| L | 140 | 8C | ICI | Identification Number in Context Indicator | (DIN 31626) Within a bibliographic field, used to refer to data in another bibliographic record by its ID number. |
| L | 140 | 8C | PLU | Partial Line Up | (ISO 6630) Not in original edition of ISO 6630. In the 1985 edition of ISO 6630, used for Partial Line Up (see PLU). |
| M | 141 | 8D | OSC | Optional Syllabification Control | (DIN 31626) Marks a syllable boundary in a long word. See also soft hyphen. |
| M | 141 | 8D | ZWJ | Joiner | (MARC 21) In MARC-8, used for the Zero-Width Joiner, while U+200D is used in Unicode-format MARC records. |
| N | 142 | 8E | SS2 | Single-Shift 2 | (DIN 31626) Non-locking shift code, see SS2. |
| N | 142 | 8E | ZWNJ | Non-Joiner | (MARC 21) In MARC-8, used for the Zero-Width Non-Joiner, while U+200C is used in Unicode-format MARC records. |
| O | 143 | 8F | SS3 | Single-Shift 3 | (DIN 31626) Non-locking shift code, see SS3. |
| P | 144 | 90 | - | (reserved) | |
| Q | 145 | 91 | EAB | Embedded Annotation Beginning | (DIN 31626, ISO 6630) Marks the start of a variable-length annotation which is embedded within a bibliographic field, as opposed to separated using content designation. |
| R | 146 | 92 | EAE | Embedded Annotation End | (DIN 31626, ISO 6630) Marks the end of a variable-length embedded annotation. |
| S | 147 | 93 | ISB | Item Specification Beginning | (DIN 31626) Marks the start of a string of specific information of some description, other than a keyword or a permutation string. |
| T | 148 | 94 | ISE | Item Specification End | (DIN 31626) Marks the end of a string of specific information. |
| U | 149 | 95 | SIB | Sorting Interpolation Beginning | (ISO 6630) Marks the beginning of a sequence of characters used for collation purposes only. |
| V | 150 | 96 | SIE | Sorting Interpolation End | (ISO 6630) Marks the end of a sequence of characters used for collation purposes only. |
| W | 151 | 97 | SSB | Secondary Sorting Value Beginning | (ISO 6630) Marks the start of a string with subordinate collation value. |
| X | 152 | 98 | SSE | Secondary Sorting Value End | (ISO 6630) Marks the end of a string with subordinate collation value. |
| Y | 153 | 99 | INC | Indicator for Non-Standard Character | (DIN 31626) Identifies a following non-standard character. |
| Z | 154 | 9A | - | (reserved) | |
| [ | 155 | 9B | - | (reserved) |
| \ | 156 | 9C | KWB | Keyword Beginning | (DIN 31626, ISO 6630) Marks the start of a keyword within a bibliographic field. |
| ] | 157 | 9D | KWE | Keyword End | (DIN 31626, ISO 6630) Marks the end of a keyword within a bibliographic field. |
| ^ | 158 | 9E | PSB | Permutation String Beginning | (DIN 31626, ISO 6630) Marks the start of a string which is to be permuted to the front of the element when references or indices are generated. Terminated by PSE or by the end of the element. |
| _ | 159 | 9F | PSE | Permutation String End | (DIN 31626, ISO 6630) Marks the end of a string which is to be permuted to the front of the element. |