---
title: "Code pages"
description: "EBCDIC, DOS 437, Latin-1 and Windows-1252. Read bytes as text in another character set or turn mojibake back into what it was"
canonical_url: "https://encodings.agntn.dev/guide/code-pages"
---
# Code pages

> EBCDIC, DOS 437, Latin-1 and Windows-1252. Read bytes as text in another character set or turn mojibake back into what it was

## Bytes in a different character set

Every encoding here writes bytes as text. A code page doesn't. It says which character each byte already is. Byte `0xC8` is `È` in Latin-1 and `H` on an IBM mainframe. Same byte, different letter.

```ts
import { charsets, hex } from "@agntn/encodings";

charsets.toText(hex.decode("c8c5d3d3d640e6d6d9d3c4"), { codepage: "ibm037" });
// "HELLO WORLD"
charsets.fromText("Grüße", { codepage: "ibm273" });
// Uint8Array [0xc7, 0x99, 0xd0, 0xa1, 0x85]
```

`toText` reads bytes, one character each. `fromText` goes back. A character the page doesn't have throws a `DecodeError` with its index. No `?`, no guess.

## Which pages?

<table>
<thead>
  <tr>
    <th>
      <code>
        codepage
      </code>
    </th>
    
    <th>
      What it is
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ibm037
      </code>
    </td>
    
    <td>
      EBCDIC for the US and Canada
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ibm273
      </code>
    </td>
    
    <td>
      EBCDIC for Germany and Austria, with <code>
        ä
      </code>
      
      , <code>
        ö
      </code>
      
      , <code>
        ü
      </code>
      
       and <code>
        ß
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ibm500
      </code>
    </td>
    
    <td>
      EBCDIC, the international one
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ibm1140
      </code>
      
      , <code>
        ibm1141
      </code>
    </td>
    
    <td>
      037 and 273 with <code>
        €
      </code>
      
       on byte <code>
        0x9F
      </code>
      
      , where <code>
        ¤
      </code>
      
       used to be
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ibm437
      </code>
    </td>
    
    <td>
      The DOS page. Box drawing, Greek and accents up top, plain ASCII below
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        latin1
      </code>
    </td>
    
    <td>
      ISO 8859-1. Byte <code>
        n
      </code>
      
       is code point <code>
        n
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        windows1252
      </code>
    </td>
    
    <td>
      What a browser calls Latin-1. Smart quotes and <code>
        €
      </code>
      
       on <code>
        0x80
      </code>
      
       to <code>
        0x9F
      </code>
    </td>
  </tr>
</tbody>
</table>

The EBCDIC tables come from IBM's own mappings, checked against glibc `iconv`. The `ibm437` table also matches glibc `iconv` byte for byte. Forget DOS screen glyphs: below `0x20` sit plain ASCII controls, so `0x01` isn't ☺. Windows-1252 reads the five bytes Microsoft never assigned as the C1 controls, the way every browser does.

## Old ZIP names

PKWARE's APPNOTE says ZIP names use code page 437 when general purpose bit 11, the UTF-8 flag, isn't set. Read `434146902e545854` as UTF-8 and you get `CAF�.TXT`.

```ts
charsets.toText(hex.decode("434146902e545854"), { codepage: "ibm437" });
// "CAFÉ.TXT"
```

`ibm437` brings the café back: `CAFÉ.TXT`.

## Mojibake

Mojibake is text shown in the wrong code page. So you undo it in two steps. Read the text in the page it was shown in, then read those bytes in the page they were written in.

```ts
const bytes = charsets.fromText("ÎÈ,Îø%_", { codepage: "ibm1141" });
new TextDecoder().decode(bytes);
// "vtkvplm"
```

Plain ASCII letters, printed as EBCDIC 1141. That's how a puzzle hides a Beaufort ciphertext in plain sight. Looks like line noise, turns out to be lowercase letters. Which page was it? Nothing in the text tells you, so `identify` doesn't guess. Try the likely ones.

## CLI and agents

```bash
encodings convert c8c5d3d3d640e6d6d9d3c4 --from hex --to ibm037
# HELLO WORLD

encodings convert 'ÎÈ,Îø%_' --from ibm1141
# vtkvplm
```

`--from` turns the input into bytes, `--to` writes them back, `utf8` by default. Both take a code page, `utf8`, `hex`, `base64` or `raw`. Agents get the same thing as `encodings_charset_convert`, with `text`, `from` and `to`.

```text
hex → 11 bytes → ibm037:
"HELLO WORLD"
```

The subpath is `@agntn/encodings/charsets`, if the tables are all you need.


## Sitemap

See the full [sitemap](https://encodings.agntn.dev/sitemap.md) for all pages.
