2. Binary and Digital Representation

A progressive guide to binary notation and the rules used to represent numbers, text, images, and sound as digital data.

Binary foundations and storage units

Computers represent information as patterns of bits. A has one of two possible values, 0 or 1. These values can correspond to physical states such as low or high voltage, off or on, or two magnetic orientations.

A pattern of bits has no meaning by itself. A system must interpret it as a number, character, image value, sound sample, instruction, or another kind of information. This distinction between physical storage and logical meaning is the foundation of digital representation.

Binary place values

uses base 22, whereas the decimal system uses base 1010. In a binary number, the rightmost position has value 202^0, the next position has value 212^1, and each position to the left doubles the place value. A 1 means that a place value is included; a 0 means that it is not.

For example, the binary number 1011₂ represents:

(1×23)+(0×22)+(1×21)+(1×20)=8+0+2+1=1110(1\times2^3)+(0\times2^2)+(1\times2^1)+(1\times2^0)=8+0+2+1=11_{10}

The subscripts identify the bases: 1011₂ is binary and 11₁₀ is decimal.

Bits, bytes, and storage units

A is one binary digit. A contains eight bits, so it has 28=2562^8=256 possible patterns. An unsigned represents decimal values from 00 through 255255.

Common powers-of-two storage units include 2102^{10} bytes for a kibibyte, 2202^{20} bytes for a mebibyte, and 2302^{30} bytes for a gibibyte. The terms kilobyte, megabyte, and gigabyte may also refer to decimal quantities based on powers of 1,0001{,}000.

Takeaway: Binary provides the patterns, but an interpretation rule is needed to give each pattern meaning.

Converting and storing binary numbers

Binary-to-decimal conversion uses the place values marked with 1. Multiply each binary digit by its corresponding power of 22, then add the results.

For example:

110012=(1×24)+(1×23)+(0×22)+(0×21)+(1×20)11001_2=(1\times2^4)+(1\times2^3)+(0\times2^2)+(0\times2^1)+(1\times2^0)
16+8+0+0+1=2516+8+0+0+1=25

Therefore, 110012=251011001_2=25_{10}.

To convert decimal to binary, repeatedly divide by 22 and record each remainder. Read the remainders from bottom to top. For 251025_{10}, the successive remainders are 1, 0, 0, 1, and 1, which produce 11001₂ when read upward.

A second method is to select powers of 22 that add to the target value. Since

25=16+8+1=24+23+2025=16+8+1=2^4+2^3+2^0

the positions from 44 through 00 contain 1, 1, 0, 0, and 1.

Fixed-width storage

In a fixed-width representation, a value is stored using a predetermined number of bits. The value 55 can be written as 101₂, but an eight- stores it as 00000101₂. The leading zeros do not change the value; they fill the available positions.

A pattern does not automatically reveal whether it represents a positive integer, a negative integer, or a fraction. The representation rules must be known. For example, an unsigned eight- value ranges from 00 through 255255, while signed conventions such as two's complement use some patterns for negative values.

Takeaway: Conversion depends on place values, and storage depends on the width and numerical convention used.

Numbers, precision, and interpretation

Digital systems use different rules to represent different kinds of numerical values. For nonnegative integers, each binary position contributes a power of 22. Fractions use positions after a binary point, such as 2−12^{-1}, 2−22^{-2}, and 2−32^{-3}.

Signed integers use conventions such as two's complement to assign negative meanings to some patterns. Real-number approximations commonly use floating-point formats with fields for a sign, an exponent, and a fraction. Floating-point formats cover a wide range of values, but they cannot represent every real number exactly.

The number of available bits limits both range and precision. More bits provide more distinct patterns, but they also require more storage. Choosing a representation therefore involves balancing the values that must be represented, the required accuracy, and the storage available.

Representation rules

A defines how a pattern should be interpreted. Its rules may specify the data type, layout, encoding, size, order, and required metadata. Without these rules, the same pattern can support several valid interpretations.

For example, the same eight bits could represent an unsigned decimal number, a character, a grayscale value, part of a color value, part of an audio sample, or an instruction. The bits alone do not determine which meaning is intended.

Takeaway: Digital representation is a contract between stored patterns and the rules used to interpret them.

Text and image representation

Text is represented by mapping characters to numbers and then storing those numbers as bits. An encoding system must specify which number corresponds to each character and how that number is stored.

ASCII represents a limited set of characters using numeric codes. assigns a code point to characters from many writing systems, punctuation marks, symbols, and emoji. can be stored using encoding forms such as , UTF-16, and UTF-32.

uses one to four bytes for a character. Characters in the ASCII range use one , while many other characters use two, three, or four bytes. For example, A has code point U+0041 and is represented by the single 41 in hexadecimal.

The same sequence of bits can produce different text if it is decoded using the wrong encoding. Text files and communication protocols therefore need an agreed-upon character encoding.

Images as numerical data

A raster image is a rectangular grid of pixels. Each stores numerical information about brightness or color. A black-and-white image may use one per . A grayscale image may use several bits per ; with 88 bits, it can represent 28=2562^8=256 shades.

Color images commonly use separate red, green, and blue channels. If each channel uses 88 bits, the image uses 2424 bits per and can represent up to:

256×256×256=16,777,216256\times256\times256=16{,}777{,}216

RGB color combinations before transparency and other color-management details are considered. Greater spatial resolution means more pixels, while greater means more possible brightness or color values per . Both generally increase the amount of data.

Vector images use mathematical descriptions of shapes, lines, and curves rather than storing every . The display system calculates pixels when the image is rendered.

Takeaway: Text and images both use bits, but their formats define different mappings between numerical patterns and visible characters or colors.

Digital sound and the common representation model

Sound begins as a continuously varying analog signal. To store it digitally, a computer repeatedly measures the signal through sampling. Each measurement is assigned a numerical value through and stored in binary.

The is the number of measurements taken per second. A rate of 44.1 kHz44.1\text{ kHz} means 44,10044{,}100 samples per second. is the number of bits used for each sample; a larger allows more possible amplitude values and a wider range of signal levels.

Digital audio may contain multiple channels, such as left and right stereo channels. For one second of uncompressed stereo audio at 44,10044{,}100 samples per second, 1616 bits per sample, and 22 channels, the amount of data is:

44,100×16×2=1,411,200 bits44{,}100\times16\times2=1{,}411{,}200\text{ bits}

This equals 176,400176{,}400 bytes before file headers and other metadata. The stored amount depends on , , number of channels, and duration.

Sampling and are approximations. Increasing the can capture changes that occur more quickly, while increasing provides finer measurement levels. Compression can reduce stored size, sometimes by removing information judged less noticeable.

One principle across all media

Numbers, text, images, and sound are all ultimately stored as patterns. Their meanings differ because each format supplies different interpretation rules. A format may need to identify dimensions for an image, sampling information for audio, or character encoding for text.

Takeaway: Digital media differ in their encoding methods, but every format connects binary storage to a defined interpretation.