Encodings

Binary

Eight bits per byte spelled out in zeros and ones. Spaces between bytes by default
IDbinary01 / 20binary · 2 characters
Encoding / Binary

Binary

Every bit spelled out. Eight characters a byte.

Overhead
+700% on random bytes
Padding
none
Standard
Base2, most significant bit first
Family
1 in binary
family 1 / 20

Sample

Out
01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100 00100001
Back
"hello world!"

Options

separateboolean
default true
Put a space between bytes
symbolsstring
default 01
The character for 0, then the one for 1, such as ab
bitsnumber
default 8
Bits per byte, from 1 to 8; 7 for 7-bit ASCII
orderstring
default msb
Most or least significant bit first

Access

Importimport { binary } from "@agntn/encodings/binary"
CLIencodings encode binary 'hello world!'
Tryplayground with the sample above

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?