---
title: "Decimal"
description: "Numbers can be bytes or Unicode code points. Give the ASCII table some company"
canonical_url: "https://encodings.agntn.dev/encodings/decimal"
---
# Decimal

> Numbers can be bytes or Unicode code points. Give the ASCII table some company

<encoding-facts name="decimal">



</encoding-facts>

The ASCII table, written out. `72` is `H`, `105` is `i`. You've seen it a hundred times.

```ts
encode("decimal", "Hi");                       // "72 105"
encode("decimal", "Hi", { separate: false });  // "072105"
```

Spaces or commas between numbers, both read the same. Without any separator, decimal can't tell `1 2` from `12`. So `separate: false` pads every byte to three digits, and decoding reads a run three at a time. Four digits in a row? That's an error, not a guess.

Anything over `255` doesn't fit a byte, and you get the index of it.

## Need Unicode code points instead of bytes?

Got Polish letters in your puzzle? Set `codepoints: true` to read each number as a Unicode code point. The decoded text comes back as UTF-8 bytes. Encoding takes UTF-8 text and writes a number for each character. Much nicer than making `ż` wait outside the ASCII table.

```ts
decode("decimal", "90 97 380 243 322 263", { codepoints: true }).bytes;  // Uint8Array [90, 97, 197, 188, 195, 179, 197, 130, 196, 135], "Zażółć"
encode("decimal", "Zażółć", { codepoints: true });                      // "90 97 380 243 322 263"
```

By default, `decimal` reads bytes from 0 to 255. That distinction matters even below 256. `233` can be a byte or a character, depending on the option.

```ts
decode("decimal", "233").bytes;                        // Uint8Array [233]
decode("decimal", "233", { codepoints: true }).bytes;  // Uint8Array [195, 169], é in UTF-8
```

Code points are always encoded with spaces. They have no fixed width, so `separate: false` doesn't apply. Decoding accepts spaces, commas and leading zeros.

The decoder refuses values above 1114111 and surrogates from 55296 to 57343. The error includes the number's index. So `55356 57225`, the UTF-16 halves of 🎉 from JavaScript's `charCodeAt`, is refused. The whole emoji is code point `127881`. In byte mode, values above 255 produce an error ending with `for Unicode code points, such as 380 for ż, set codepoints`.


## Sitemap

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