---
title: "Binary"
description: "Eight bits per byte spelled out in zeros and ones. Spaces between bytes by default"
canonical_url: "https://encodings.agntn.dev/encodings/binary"
---
# Binary

> Eight bits per byte spelled out in zeros and ones. Spaces between bytes by default

<encoding-facts name="binary">



</encoding-facts>

The most honest encoding there is. Every bit, out loud, most significant first.

```ts
encode("binary", "Hi");                       // "01001000 01101001"
encode("binary", "Hi", { separate: false });  // "0100100001101001"
```

Decoding skips whitespace, so both forms read back the same. A count that isn't a multiple of eight is an error, not a guess about where the missing bits went. Puzzles love this one. Ever counted zeros by hand at 2am? Don't.

## Other symbols

Not every puzzle writes its bits as `0` and `1`. Some use `a` and `b`, some moons, some card suits. `symbols` takes any two characters, zero first.

```ts
decode("binary", "abaabaaa abbabaab", { symbols: "ab" }).bytes;  // "Hi" as bytes
encode("binary", "Hi", { symbols: "🌑🌕" });  // "🌑🌕🌑🌑🌕🌑🌑🌑 🌑🌕🌕🌑🌕🌑🌑🌕"
```

Whitespace still doesn't count, so neither symbol can be a space. Zero-width characters are fine though, for that text that looks empty and isn't. An emoji with its variation selector, `♥️`, counts as one symbol.

## Fewer bits, other order

Old 7-bit ASCII drops the leading zero of every byte. `bits: 7` reads it, and anything from 1 to 8 works. `order: "lsb"` flips each group, for text written least significant bit first.

```ts
encode("binary", "Hi", { bits: 7 });                  // "1001000 1101001"
encode("binary", "Hi", { order: "lsb" });             // "00010010 10010110"
decode("binary", "0001001 1001011", { bits: 7, order: "lsb" });
```

A byte that doesn't fit in fewer bits throws instead of losing its top bit. `identify` tries `lsb` on its own. Symbols and bit counts it leaves to you, because who could guess that moons mean zero?


## Sitemap

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