Skip to main content

Command Palette

Search for a command to run...

What the heck is binary?

Published
View as Markdown

ASCII

ASCII = American Standard Code for Information Interchange is a character encoding using 7 bits to represent 128 characters. It’s a character encoding that maps text into a number.

Example:

CharASCII
A65
a97
048

It's how text is stored in memory as bytes.

Base64

Base64 turns binary into an ASCII string.

Base64 encoding schemes are commonly used to encode binary data for storage or transfer over media that can only deal with ASCII text

btoa

https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa

The btoa() method of the Window interface creates a Base64-encoded ASCII string from a binary string

const str = "Hello";
const encoded = btoa(str); // base64 encode
console.log(encoded); // "SGVsbG8="

atob

The atob() method of the Window interface decodes a string of data which has been encoded using Base64 encoding

const decoded = atob(encoded); // decode
console.log(decoded); // "Hello"

Use case

  1. Embed Images in HTML/CSS

  2. Send Binary Data via JSON or GraphQL

  3. Save Binary in local-storage

  4. Transfer Binary via URL

{
  "filename": "photo.jpg",
  "content": "base64string..."
}

Binary

Binary is a raw data represented in bits (0s and 1s)

Blob

Binary Large Object — a container for binary data. Blob is binary data plus metadata like MIME type.

Readable stream

https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream