Binary and Data Representation

Learn how computers turn numbers, text, pictures and sound into bits. Convert between decimal, binary and hexadecimal; store whole numbers as unsigned and two's complement integers; encode real numbers in IEEE 754 floating point and see why 0.1 + 0.2 is not exactly 0.3; encode text with ASCII and Unicode (UTF-8); calculate how much storage images, video and sound need; and see how lossless and lossy compression make files smaller.

BeginnerLesson 2 of 7 in Introduction to Computer Science Course

What you will learn

  1. Explain how groups of bits encode information, and convert whole numbers between decimal, binary and hexadecimal.
    • Explain bits, bytes and how many values a group of bits can hold
      Describe bits and bytes, work out how many patterns a number of bits gives, and read storage and speed units correctly.
    • Convert whole numbers between decimal and binary
      Use place values to read binary numbers, and convert decimal whole numbers to binary with two reliable methods.
    • Use hexadecimal as a shorthand for binary
      Convert between hexadecimal, binary and decimal, and explain why programmers write bytes, colors and addresses in hexadecimal.
  2. Store non-negative and negative integers in a fixed number of bits, work out their ranges, and explain what happens when a value does not fit.
    • Store unsigned integers and recognize their range
      Represent non-negative whole numbers in a fixed width, choose a width that fits the values, and explain overflow.
    • Represent negative integers in two's complement
      Read and write negative whole numbers in two's complement, find the range of a signed width, and compare it with sign-magnitude.
  3. Write fractions in binary, encode and decode numbers in the IEEE 754 floating-point formats, and explain the limits on their range and precision.
    • Write fractions in binary and see why some cannot be exact
      Convert between decimal and binary fractions, recognize repeating binary fractions such as 0.1, and describe fixed-point numbers.
    • Encode and decode IEEE 754 floating-point numbers
      Use binary scientific notation and the sign, exponent and fraction fields of the IEEE 754 single- and double-precision formats.
    • Explain range, precision and rounding error in floating point
      Explain why floating-point values are approximations, predict typical effects such as 0.1 + 0.2, and choose a suitable number type.
  4. Explain how characters become numbers and bytes, use ASCII and Unicode, and predict how many bytes UTF-8 text takes.
    • Encode text with character codes and ASCII
      Use a character code table to turn text into numbers and bits, read the layout of ASCII, and explain its limits.
    • Use Unicode code points and UTF-8 encoding
      Distinguish a Unicode code point from its encoded bytes, encode characters in UTF-8, and explain garbled text and byte counts.
  5. Describe how pictures become pixels and color values, calculate the storage they need, and explain how sound is sampled into numbers.
    • Represent images with pixels and color values
      Describe bitmap images, color depth, RGB and hex color codes, palettes and transparency.
    • Calculate image sizes and compare bitmap with vector graphics
      Calculate the storage an uncompressed image or video needs, explain what files add, and describe vector graphics.
    • Digitize sound by sampling and quantizing
      Explain sampling, sample rate and bit depth, apply the sampling rule, and calculate the size of uncompressed audio.
  6. Explain how compression makes data smaller, apply simple lossless methods, and choose between lossless and lossy formats.
    • Explain lossless compression with run-length and other codes
      Apply run-length encoding and variable-length codes, describe dictionary methods, and explain why no method shrinks every file.
    • Explain lossy compression and choose a suitable format
      Describe how lossy compression discards less noticeable detail, weigh quality against size, and choose formats for different kinds of data.

Binary and Data Representation study guide

6 chapters

1

Count patterns and change number bases

A computer can use the same group of bits for a number, a letter, or part of a picture. The interpretation gives the pattern its meaning. Before working with those interpretations, you need to count the patterns available and read the units used for storage and transfer. Decimal, binary, and hexadecimal then give you three ways to write a whole number, each with place values that make conversions predictable.

1.1 Bits, bytes, and storage units

A bit, short for binary digit, has one of two values: 0 or 1. Hardware can distinguish two physical states reliably, such as high and low voltage, opposite directions of magnetization, or light and no light. The written digits describe those states; they need not literally appear inside a device.

Count the patterns

Each new bit doubles the choices. Two bits have four patterns: 00, 01, 10, and 11. Three bits have eight. In general, n bits give 2n patterns. A nibble is 4 bits, and a byte is 8 bits, so a byte has 256 patterns. A byte is also the smallest addressable unit of memory on most modern computers.

To encode a set of values, choose enough patterns for every member. For 26 letters, four bits give only 16 patterns; five bits give 32, so five bits suffice. For 1,000 values, nine bits give 512 and ten give 1,024. Unused patterns are allowed. With 16 bits there are 65,536 patterns, and with 32 there are 4,294,967,296.

The pattern count differs from the largest unsigned number. Four bits provide 16 patterns, but counting starts at zero, so the values run from 0 through 15. One pattern is already used for zero.

To find the minimum width systematically, compare successive powers of two with the required number of choices. Stop at the first power that is large enough. The test is 2n≥N for N distinct values. Exact equality is allowed: eight choices fit in three bits, while a ninth choice needs a fourth bit. A larger width still works, but it is no longer the minimum.

Give the pattern a meaning

The byte 01000001 can mean the integer 65, the ASCII letter "A", or a color-channel intensity of 65 on a 0–255 scale. The bits alone do not select one reading. A program's data type and the file's format determine how to interpret them.

Read storage units

Two families of prefixes are common:

Decimal storageBytesBinary storageBytes
1 kB1,0001 KiB1,024
1 MB1,000,0001 MiB1,048,576
1 GB1,000,000,0001 GiB1,073,741,824

The decimal prefixes are SI prefixes; the binary prefixes are IEC prefixes. In each decimal step the unit grows by 1,000; in each binary step it grows by 1,024. To express bytes in a larger unit, divide by the number of bytes in that unit.

A drive labeled 500 GB contains 500,000,000,000 bytes. Dividing by 1,073,741,824 gives about 465.66 GiB. Software may label that binary quantity "GB", which makes the displayed capacity look smaller. The unit change itself has removed no bytes; formatting and system files are separate matters.

Distinguish bits from bytes

Lowercase b means bit; uppercase B means byte. A 100 Mbit/s connection transfers at most 100 million bits each second. Dividing by 8 gives 12.5 million bytes per second, or 12.5 MB/s, before protocol overhead. Reading that speed as 100 MB/s makes it eight times too large.

Key Takeaways

  • A byte has 8 bits; a nibble has 4.
  • Each additional bit doubles the pattern count.
  • Choose the smallest bit count for which the available patterns cover every value.
  • A data type or encoding gives a bit pattern its meaning.
  • SI storage prefixes use powers of 10; IEC prefixes use powers of 2.
  • Divide a bit rate by 8 to obtain the corresponding byte rate.

1.2 Binary place value and conversion

Binary is a positional number system: a digit's value depends on where it sits. Decimal uses ten digits and powers of 10. Binary uses two digits, 0 and 1, and powers of 2. Reading a binary number is a matter of adding the places that contain a 1.

Read a binary whole number

From right to left, the places are 1, 2, 4, 8, 16, 32, 64, 128, and so on. Each is twice the previous one because 20=1, 21=2, and 22=4.

For 1011012, line up the six bits with their places:

Place32168421
Bit101101

The value is 32+8+4+1=45. A zero contributes nothing, but it keeps the other digits in the right places. Leading zeros leave the value unchanged: 00101101 is also 45.

The leftmost bit is the most significant bit, or MSB. The rightmost is the least significant bit, or LSB. Every place except the last is even, so a binary whole number is odd exactly when its LSB is 1.

Convert by subtracting powers of two

To write 156 in binary, start with the largest power of two that fits: 128. Subtract it, leaving 28. The 64 and 32 places do not fit, so both receive 0. Take 16, leaving 12; take 8, leaving 4; take 4, leaving 0. The unused 2 and 1 places receive 0.

In place order, the result is 156=100111002. Check by adding the chosen places: 128+16+8+4=156. Skipping an unused column would move every later bit and change the number.

The subtraction method works because each binary place can be used at most once. After taking the largest fitting power, the remainder is smaller than that power. Continue downward through every place, including the zero places, until the ones place is filled. This makes the chosen bits line up with distinct powers instead of a list of powers without positions.

Convert by repeated division

Another method divides by 2 repeatedly. Keep the quotient for the next division and record the remainder:

NumberQuotientRemainder
156780
78390
39191
1991
941
420
210
101

Read the remainders from bottom to top, giving 10011100. The first remainder belongs to the ones place, so reading downward reverses the place order. Here that would produce 00111001, which is 57.

Keep the base visible

The subscript in 102 means base 2, so its value is two. The same digits in 1010 mean ten. Binary is usually read digit by digit: "one zero". Counting proceeds 0, 1, 10, 11, 100, 101, 110, 111, 1000; a column carries when it reaches 2. A string of eight ones is 28−1=255. Appending a zero shifts every place left and doubles the value: 101 becomes 1010, taking five to ten.

Key Takeaways

  • Add the powers of two whose bits are 1.
  • Leading zeros preserve a value; missing internal places do not.
  • Read repeated-division remainders from last to first.
  • A whole number is odd exactly when its least significant bit is 1.
  • Appending a zero doubles an unbounded binary whole number.

1.3 Hexadecimal as readable binary

Hexadecimal, or hex, writes numbers in base 16. Its digits are 0–9 followed by A, B, C, D, E, and F, which mean 10 through 15. A single hex digit can describe every possible group of four bits, making long binary patterns easier to read.

Match four bits to one digit

Because 16=24, each hex place corresponds to exactly four binary places:

HexBinaryHexBinary
0000081000
1000191001
20010A1010
30011B1011
40100C1100
50101D1101
60110E1110
70111F1111

For binary to hex, group from the right. The pattern 10011100 becomes 1001 1100, or 0x9C. For a shorter final group on the left, add leading zeros: 101101 becomes 0010 1101, or 0x2D. Grouping it from the left as 1011 01 would put the digits in the wrong places.

To go back, expand every digit to four bits. Thus 0x3E8 becomes 0011 1110 1000. Keep all four bits inside each group, even when a group begins with zeros. Only zeros at the far left of the whole number can be dropped without changing its value.

Use base-16 place values

From right to left, hex places are 1, 16, 256, and 4,096. Multiply each digit's value by its place, then add. For 0x2F, the calculation is 2×16+15=47. For 0x3E8:

3×256+14×16+8=768+224+8=1000

Decimal to hex also works by repeated division, now by 16. For 1,000, the first quotient is 62 with remainder 8. Dividing 62 gives quotient 3 with remainder 14, written E. Dividing 3 gives quotient 0 with remainder 3. Read the remainders upward: 3, E, 8.

The grouping works through place value, not just a matching table. In a two-digit hex number, the left nibble contributes its value times 16, and the right nibble contributes its value times 1. In binary, shifting a nibble four places left also multiplies its value by 16. That shared factor lets the two groups be read independently without converting the whole number to decimal first.

Recognize common uses

One byte is two nibbles, so it is exactly two hex digits, from 0x00 to 0xFF. A byte viewer can show a long file four times more compactly in hex than in binary while keeping the group boundaries visible.

Web colors such as #FF8000 use pairs of hex digits for red, green, and blue. Memory addresses and Unicode code points such as U+00E9 also use hex. A MAC address such as 3C:22:FB:9A:01:7E writes six bytes as twelve hex digits, with separators between the bytes.

The prefix 0x, a base subscript such as 2F16, or the # in a color code identifies the notation. The computer stores the same bits whichever notation a person uses. In particular, 0x10 means sixteen. The value fifteen is the single digit F; writing "15" occupies two hex places and means twenty-one.

Key Takeaways

  • Hex uses 0–9 and A–F, with A–F representing 10–15.
  • Group binary from the right in fours to convert to hex.
  • One byte is exactly two hex digits.
  • Hex place values are powers of 16; changing notation does not change the stored bits.
2

Store whole numbers in a fixed width

A fixed number of bits can hold only a fixed set of whole numbers. The chosen interpretation decides whether all those patterns represent nonnegative values or whether some represent negative values. You will read the same byte both ways, choose widths that fit a required range, and follow what happens at the endpoints. Two's complement also explains how negative values keep their meaning when their width grows.

2.1 Unsigned values and overflow

An unsigned integer represents a nonnegative whole number. All its bits have ordinary positive binary weights. The width fixes how many places are available, so a byte cannot grow a ninth bit just because a result needs one.

Find the range

For n bits, there are 2n patterns. Starting at zero gives the range 0 to 2n−1. The largest value has a 1 in every place:

WidthUnsigned range
8 bits0–255
16 bits0–65,535
32 bits0–4,294,967,295

The number of available values and the maximum value differ by one. Eight bits allow 256 choices, but 256 itself needs nine places, 1 0000 0000.

A stored value fills its width with leading zeros. For example, 45 in 16 bits is 0000000000101101, or 0x002D. Those zeros identify the width without changing the value. A negative number has no unsigned representation, whatever width you choose.

Choose enough places

An age range of 0 through 150 fits in 8 bits because 150 is below 255. A count from 0 through 100,000 contains 100,001 possible values. Sixteen bits offer only 65,536 patterns. Seventeen offer 131,072, so 17 is the minimum mathematical width. A program using common widths of 8, 16, 32, and 64 would choose 32 bits.

The same reasoning applies to any bounded counter: check the largest value the counter must actually hold, including both endpoints. A range of 0 through 256 needs 257 patterns and therefore will not fit in one byte.

A useful boundary check compares adjacent widths. The unsigned maximum for 8 bits is 255, and for 9 bits it is 511. Adding a bit doubles the number of patterns; the maximum becomes twice the old maximum plus one. This distinction matters when a requirement lands exactly on a power of two: that endpoint needs a new place even though the previous width has that many patterns.

Follow a result beyond the range

Overflow means that a result does not fit the chosen representation. If an 8-bit calculation keeps only the lowest eight bits, 255 plus 1 produces 1 0000 0000 and stores 00000000: zero. The extra place is discarded.

For 200 plus 100, the mathematical result is 300. The width keeps the remainder after a full cycle of 256 patterns: 300−256=44. The stored byte is 00101100. This behavior is called wraparound. It does not change the arithmetic fact that 200 plus 100 is 300; it describes what the limited storage retains.

Overflow behavior depends on the system. Some operations wrap, some signal an error, and some number types grow. A calculation asking about wraparound must identify that behavior before you discard high bits.

See fixed widths in data

An IPv4 address has 32 bits, giving about 4.3 billion possible patterns. That finite address space helped drive the need for a larger addressing system. An ordinary RGB color channel has 8 bits, which explains its 0–255 intensity scale. The maximum in both cases follows from the width; a longer decimal spelling adds no storage capacity.

Key Takeaways

  • An unsigned n-bit integer ranges from 0 to 2ⁿ − 1.
  • Count both endpoints when selecting a width.
  • Leading zeros fill a width without changing an unsigned value.
  • Overflow means a result falls outside the representable range.
  • When a system keeps only the low n bits, unsigned values wrap in cycles of 2ⁿ.

2.2 Negative integers in two's complement

A negative integer needs a representation rule, not just a minus sign written beside a byte. Two's complement gives the top bit a negative weight. The remaining places keep their positive weights, so every pattern has one signed value and zero has one pattern.

Compare two signed readings

A simpler scheme, sign-magnitude, uses the top bit only for the sign and the remaining bits for the size. In 8 bits, +5 is 00000101 and −5 is 10000101. It has two zeros, 00000000 and 10000000, and mixed-sign addition needs extra rules.

In 8-bit two's complement, the weights are −128, 64, 32, 16, 8, 4, 2, and 1. Thus 11010011 means −128+64+16+2+1=−45. Reading the other seven bits as a magnitude of 83 would give −83, which belongs to a different representation.

WidthTwo's complement range
8 bits−128–127
16 bits−32,768–32,767
32 bits−2,147,483,648–2,147,483,647

In general the range is −2n−1 to 2n−1−1. Zero and positive values look like ordinary binary with a leading 0. All ones represent −1.

Write a negative value

To negate a representable value, invert every bit and add 1, keeping the width fixed. To encode −45 in 8 bits:

  1. Write +45 as 00101101.
  2. Invert all eight bits: 11010010.
  3. Add 1: 11010011, or 0xD3.

Stopping after inversion produces −46. Applying the full process to 11010011 gives 00101101 again, recovering +45.

Another route encodes −x as the unsigned value 2n−x. Here 256−45=211, whose binary form is 11010011. The byte therefore means 211 unsigned or −45 signed. The bits have not changed; the type has.

Inversion followed by addition also has an arithmetic explanation. For an n-bit positive value x, inversion changes it to the unsigned value 2n−1−x. Adding one gives 2n−x, whose signed interpretation is −x. This connects the bit-by-bit method to the subtraction method and explains why leaving out the final 1 gives the wrong negative value.

Preserve a signed value in more bits

Sign extension copies the top bit into the new places on the left. Four-bit −3 is 1101; in 8 bits it is 11111101. Its negative top weight and added positive weights still total −3. Padding it with zeros would give 00001101, or +13. Positive values extend with zeros: 0011 becomes 00000011.

Recognize the endpoints

Two's complement supports ordinary binary addition for results that fit. In 4 bits, 0101 plus 1101, meaning 5 plus −3, gives 1 0010. Keeping the low four bits gives 0010, or 2. This lets the same basic addition hardware handle signed and unsigned values.

An out-of-range result is different: 8-bit 127 plus 1 leaves 10000000, which reads as −128. Also, −128 has no positive counterpart in 8 bits. Inverting 10000000 and adding 1 returns 10000000 because +128 is outside the range. Widen the representation before forming that positive value.

Key Takeaways

  • The top bit has weight −2ⁿ⁻¹ in n-bit two's complement.
  • Two's complement has one zero and one more negative value than positive values.
  • Negate by inverting every bit and adding 1 within the fixed width.
  • Sign extension copies the top bit into added positions.
  • The most negative value has no positive counterpart in the same width.
  • The same pattern can have different signed and unsigned meanings.
3

Store fractions and floating-point values

Whole-number places extend to the right of the binary point as halves, quarters, and smaller fractions. Some decimal fractions end in binary, while others require an endless pattern. Fixed point reserves a set number of fraction places; floating point stores a scale as well as a significand. Reading these formats makes both their wide range and their rounding errors understandable, including the familiar result of adding 0.1 and 0.2.

3.1 Binary fractions and fixed point

The first place after the binary point is one half. Each later place is half the one before: one quarter, one eighth, one sixteenth, and so on. A 1 contributes that fraction; a 0 leaves it out. The whole-number places to the left keep their usual powers of two.

Read and build a binary fraction

For 101.1012, the whole part is 4 plus 1. The fraction part is one half plus one eighth, giving 4+1+0.5+0.125=5.625.

To convert a decimal fraction, multiply it by 2 repeatedly. The whole part of each result is the next binary digit; keep only the fractional part for the next multiplication. For 0.375:

  1. 0.375×2=0.75, so the first bit is 0.
  2. 0.75×2=1.5, so the next bit is 1; keep 0.5.
  3. 0.5×2=1.0, so the next bit is 1 and the process stops.

The result is 0.0112. Its value is one quarter plus one eighth, or 0.375. These bits are read in the order found, unlike the remainders in whole-number division.

Decide whether the expansion ends

Reduce the fraction to lowest terms. It has a finite binary expansion exactly when its denominator is a power of 2. Values such as 0.5, 0.25, 0.75, and 0.375 meet that test. For example, 0.375 is 3/8, and eight is a power of two.

Decimal 0.1 is 1/10. Its denominator includes a factor of 5, so its binary expansion repeats: 0.0001100110011…2. Just as one third cannot end in decimal, one tenth cannot end in binary. The short written form "0.1" therefore needs an approximation when only a limited number of binary places are available. The same issue affects 0.2 and 0.3.

The denominator rule follows from the places themselves. A finite string ending at the fth fraction place can be written as an integer divided by 2f. Reducing that fraction can remove factors of two, but it cannot introduce another prime factor into the denominator. A reduced denominator containing five therefore cannot equal any such finite binary sum.

Reserve a fixed scale

A fixed-point representation gives a set number of bits to the fractional part. With four whole-number bits and four fraction bits, 0110.1000 means 6.5. The smallest step is 2−4=0.0625, and the largest unsigned value is 1111.1111, or 15.9375.

Equivalently, the stored eight-bit integer is scaled by 1/16. The pattern 01101000 has unsigned value 104; dividing by 16 gives 6.5. The point is part of the interpretation, so it need not be stored as an extra symbol.

Keeping eight total bits but using five whole-number bits and three fraction bits makes the step 0.125 and the maximum 31.875. You gain range but lose fine spacing. Fixed point represents multiples of its step exactly within its range.

An exact count of cents uses a related scaling idea: 19.99 monetary units becomes the integer 1999 cents. For measurements covering very different sizes, floating point stores a movable scale, letting the same width cover a much wider range than fixed point.

Key Takeaways

  • Binary fraction places are 1/2, 1/4, 1/8, and so on.
  • Multiply a fractional part by 2 and read the whole parts in order.
  • A reduced fraction terminates in binary exactly when its denominator is a power of 2.
  • Fixed point trades range against fractional resolution at a fixed total width.

3.2 Read and write IEEE 754 fields

Floating point writes a value in binary scientific notation. For example, 6.25 is 110.012=1.10012×22. The leading part is the significand, and the exponent sets its scale. IEEE 754 defines widely used formats for storing these parts.

Know the fields
FormatTotalSignExponentFractionBias
Single, binary3232 bits1823127
Double, binary6464 bits111521023

For a normal value, the reading is (−1)s×(1.f)2×2E−bias. Here s is the sign bit, E is the unsigned stored exponent, and f is the fraction field. A sign bit of 0 means positive; 1 means negative. Changing only the sign bit negates a floating-point value.

The stored exponent equals the true exponent plus the bias. In single precision, exponent 2 becomes 129, or 10000001; exponent −3 becomes 124, or 01111100. Normal stored exponents run from 1 to 254, representing −126 through 127.

A normal binary significand always begins with 1, so the format omits that hidden bit. Only the bits after the point enter the fraction field. This gives 24 significant binary digits in single precision and 53 in double.

Encode −6.25 step by step

First normalize its magnitude: 110.012=1.10012×22. Then fill the fields:

  1. Negative value: sign 1.
  2. Exponent 2: add 127 to get 129, written 10000001.
  3. Fraction .1001: store 1001 followed by 19 zeros.

The result is 1 10000001 10010000000000000000000, or 0xC0C80000. Fraction padding goes on the right because these places continue after the point. Storing the leading 1 would shift the fraction's meaning.

A negative true exponent moves the scale below one. For 0.15625, the binary form is 0.001012=1.012×2−3. Its binary32 sign is 0 and its stored exponent is 124, or 01111100. The fraction starts 01 and is padded on the right. The hidden 1 still belongs to the normalized significand even though the complete number is smaller than one.

Decode a pattern

The single-precision pattern 0x41200000 splits into 0 10000010 01000000000000000000000. The sign is positive. The exponent field is 130, so subtract 127 to obtain 3. Restore the hidden 1 to get 1.012=1.25. Finally, 1.25×23=10.

Check reserved exponents first

The normal formula does not describe every pattern:

Exponent fieldFraction fieldMeaning
All zerosZero+0 or −0, selected by sign
All zerosNonzeroA subnormal value, with leading 0
All onesZeroPositive or negative infinity
All onesNonzeroNaN, "not a number"

Subnormals represent very small values without the hidden 1. NaN can result from an invalid numerical operation such as 0 divided by 0. IEEE 754-2019 defines these formats.

Key Takeaways

  • Single precision has fields of 1, 8, and 23 bits; double has 1, 11, and 52.
  • Subtract the exponent bias when decoding; add it when encoding.
  • Normal values have an unstored leading 1.
  • Right-pad the fraction field with zeros.
  • Exponent fields of all zeros or all ones have special meanings.
  • Floating-point sign and exponent fields are not a two’s complement integer.

3.3 Range, precision, and rounding error

A floating-point format can cover a vast range without representing every value in that range. The exponent controls scale; the fraction field controls how many significant bits distinguish nearby values. Range and precision answer different questions.

Compare single and double precision

Single precision reaches about 3.4×1038 and has about seven significant decimal digits. Its smallest positive normal value is about 1.18×10−38. Double reaches about 1.8×10308, has about 15–16 significant decimal digits, and has a smallest positive normal value of about 2.2×10−308. Subnormal values extend below the normal minimum in each format.

Significant digits are counted from the first meaningful digit, not from the decimal point. A large exponent does not create more fraction bits. In single precision the gap above 1 is 2−23≈1.19×10−7. Between 224 and 225 the gap is 2, so the integer 16,777,217 is unavailable even though it lies far below the maximum finite value.

Round to a value that fits

IEEE 754's default is round to nearest, ties to even. Choose the nearer representable value; at an exact halfway point, choose the one whose last retained significand bit is even. Thus 16,777,217 rounds to 16,777,216 in single precision.

The gap between the intended value and the stored value is rounding error. In single precision, 0.1 is stored as 0.100000001490116119384765625. In double it is approximately 0.10000000000000000555. More precision reduces this error but cannot make a repeating expansion terminate.

Understand a familiar result

With ordinary IEEE 754 double arithmetic, adding 0.1 and 0.2 produces a stored result commonly displayed as 0.30000000000000004. It differs from the stored approximation of 0.3, so 0.1 + 0.2 == 0.3 is false in languages such as Python and JavaScript. For measured results, compare the difference with a tolerance chosen for the scale and purpose of the task.

Many values are exact. Double precision holds every integer from −253 through 253 exactly. Values such as 0.5 and 0.375 also have short binary forms that fit both its significand and exponent range.

Choose a suitable number type

Counts and identifiers suit integers. Exact financial amounts suit whole minor units, such as cents, or a decimal number type. Measurements and scientific calculations often suit floating point. A magnitude too large for the format can overflow to infinity; under the default rounding rule, single-precision 1039 becomes positive infinity. Very small results may become subnormal or round to zero.

Display conventions are separate from storage. The spellings "3.14" and "3,14" can name the same number in different locales. A text reader must know that convention; it might otherwise reject the comma or read the value as 314. Changing the printed separator does not improve binary precision.

Key Takeaways

  • Range controls magnitude; precision controls the spacing of nearby values.
  • Floating-point gaps grow as magnitude grows.
  • The default rounding rule is nearest, with exact ties going to an even last bit.
  • A short decimal fraction can still need rounding in binary.
  • Choose integer, decimal, or floating-point storage to match the task.
4

Turn characters into codes and bytes

Text needs an agreement between the software that writes it and the software that reads it. ASCII gives a small set of characters numeric codes. Unicode provides a shared code space for many writing systems, while encodings such as UTF-8 determine the actual bytes. Distinguishing a displayed character from a code point and from a byte helps you calculate text sizes and explain why a correctly saved file can appear garbled.

4.1 ASCII codes and their limits

To store text, a system assigns characters numeric codes and writes those numbers as bits. A character code only works when the reader uses the same agreement as the writer. The byte for a letter is a coded label; it is not a tiny picture of that letter.

Read the ASCII table

ASCII, the American Standard Code for Information Interchange, was first published in 1963. It uses 7 bits for 128 codes, numbered 0–127. In byte-based storage, an ASCII code usually fills one byte with a leading 0.

CodesMeaning
0–31 and 127Control characters
32Space
48–57Digits "0"–"9"
65–90Uppercase "A"–"Z"
97–122Lowercase "a"–"z"

Punctuation occupies the gaps. Codes 32–126 form 95 printable characters, including space. Controls affect text handling without printing a visible symbol: tab is 9, line feed is 10, and carriage return is 13.

Encode a short string

The text "Hi!" has three characters. Their decimal codes are 72, 105, and 33; in hex they are 0x48, 0x69, and 0x21. As full bytes, the text becomes 01001000 01101001 00100001. The exclamation mark needs a code just as the letters do.

A lowercase ASCII letter's code is 32 above its uppercase version. "A" is 65, or 01000001, while "a" is 97, or 01100001. That single changed bit accounts for the difference. The ordering also puts all uppercase letters before all lowercase letters. A simple code-based sort therefore places "Zebra" before "apple"; it does not follow ordinary dictionary ordering.

Separate a digit from a number

The character "7" has decimal code 55 and byte 00110111. The integer 7 has byte 00000111. To recover a digit's numeric value from its ASCII code, subtract 48, the code for "0": 55−48=7. This works because the ten digit codes are consecutive.

Storage depends on which representation is chosen. The text "2026" needs four ASCII bytes, one per digit. The integer 2026 fits in two bytes as a 16-bit unsigned value. Text preserves the sequence of characters; an integer represents the numerical value. For example, a text identifier can preserve leading zeros that an integer does not distinguish.

To encode a longer string, process every character in order, including spaces, punctuation, and controls. Decoding reverses the lookup one code at a time under the same table. The sequence matters: swapping two valid codes can still produce valid ASCII, but it produces different text. A successful lookup establishes that codes are recognized, not that they have the intended order or meaning.

See why code pages caused trouble

ASCII has no accented letters such as "é", "ñ", or "ü", and no Greek, Cyrillic, Arabic, or Chinese characters. Later 8-bit code pages used values 128–255 for extra symbols, but they did not agree on the additions.

For example, byte 0xE9 means "é" in Latin-1 but "й" in Windows-1251. Windows-1252 is another common code page. A byte value therefore cannot identify a non-ASCII character without knowing the encoding. Using the wrong table can produce readable-looking symbols that are still the wrong text.

Key Takeaways

  • ASCII defines 128 codes using 7 bits, usually stored one per byte.
  • Printable characters include spaces and punctuation; controls have other roles.
  • Digit characters have different codes from the integers they name.
  • Different legacy code pages can assign different characters to the same byte.

4.2 Unicode code points and UTF encodings

Unicode assigns characters from writing systems around the world a shared set of numbers called code points. "A" is U+0041, "é" is U+00E9, "Ж" is U+0416, "中" is U+4E2D, and "😀" is U+1F600. The U+ notation uses hexadecimal with at least four digits.

Separate a code point from its bytes

The code space runs from U+0000 to U+10FFFF, or 1,114,112 positions, with more than 150,000 assigned characters. A code point identifies a character or a reserved position; an encoding determines its byte representation.

EncodingStorage for a valid character code point
UTF-81–4 bytes
UTF-162 bytes through U+FFFF; 4 bytes above it
UTF-324 bytes

The surrogate range U+D800–U+DFFF is reserved for UTF-16's pairing mechanism; isolated surrogates are not valid characters to encode in these forms. A pair of UTF-16 code units represents one supplementary code point. For example, "😀" is D83D DE00 in UTF-16.

Read UTF-8's byte ranges

UTF-8 preserves ASCII: U+0000–U+007F use one byte. U+0080–U+07FF use two; valid character code points in U+0800–U+FFFF use three; U+10000–U+10FFFF use four. This makes English ASCII text byte-for-byte compatible with UTF-8.

A single-byte character starts with 0. Longer characters start with 110, 1110, or 11110 for two, three, or four bytes. Every continuation byte starts with 10. The remaining bits carry the code point.

For "é", U+00E9, the 11-bit value is 00011101001. Split it into five bits and six bits: 00011 and 101001. Insert them into 110xxxxx 10xxxxxx to get 11000011 10101001, or C3 A9. The code point 00E9 is not itself the UTF-8 byte sequence.

Encoding and decoding must also respect the byte prefixes. A UTF-8 continuation byte is not a standalone ASCII byte: its first two bits are 10, so it belongs inside a longer character sequence. Removing part of a multibyte character at a byte limit can leave an incomplete sequence. Storage length and the boundaries at which text can be split are therefore connected.

Count the right objects

"café" has four displayed characters but five UTF-8 bytes: 63 61 66 C3 A9. "€" uses E2 82 AC, three bytes; "中" uses E4 B8 AD, also three; "😀" uses F0 9F 98 80, four. A byte limit can therefore allow fewer characters than its numeric size suggests.

One displayed character can also contain multiple code points. "é" can be U+00E9 or "e" followed by U+0301, a combining acute accent. The second form uses three UTF-8 bytes, 65 CC 81. Normalization converts equivalent sequences to a common form for comparison. The displayed emoji "👍🏽" contains two code points, U+1F44D and U+1F3FD, totaling eight UTF-8 bytes.

Diagnose garbled text

UTF-8 "café" read as Windows-1252 becomes "café": C3 and A9 are treated as separate characters. This is mojibake, caused by decoding with the wrong encoding. Correct decoding can recover the text while the original bytes remain intact. A web page can declare its encoding with <meta charset="utf-8">.

Key Takeaways

  • A code point identifies a character; an encoding chooses its bytes.
  • UTF-8 uses one to four bytes, preserving ASCII unchanged.
  • Continuation bytes in UTF-8 begin with 10.
  • A displayed character, a code point, and a byte are different counting units.
  • Normalization can align equivalent character sequences.
  • Decoding with the wrong encoding can produce mojibake.
5

Measure pictures and sound in bits

Pictures and recordings turn visual and sound detail into numbers. A bitmap stores a grid of pixel values; sampled audio stores measurements taken at regular times. Their storage depends on how many values are kept and how many bits each value needs. These choices also affect what detail survives. Vector drawings and MIDI take a different approach by describing shapes or notes as instructions that a device later turns into an image or sound.

5.1 Pixels, RGB, palettes, and transparency

A bitmap, also called a raster image, is a grid of pixels. Each pixel holds a color value. The width and height give the image's resolution: 1920 by 1080 means 1920×1080=2,073,600 pixels. A pixel count describes the grid, not its printed size in meters.

Assign enough bits to each pixel

The color depth is the number of bits used for a pixel's color. A depth of k bits allows 2k possible codes. One bit can distinguish two colors. Eight-bit grayscale can distinguish 256 intensities, usually from 0 for black to 255 for white.

A simple 3 by 3 image can use 1 for black and 0 for white. A black plus sign is represented by rows 010, 111, and 010. Nine pixels at one bit each need nine bits of pixel information. Actual file storage may include padding and other information beyond those bits.

Mix light with RGB

RGB stores red, green, and blue light intensities. With 8 bits per channel, each intensity ranges from 0 to 255, and a pixel uses 24 bits. The number of possible colors is 2563=224=16,777,216.

RGB valuesColor
(0, 0, 0)Black
(255, 255, 255)White
(255, 0, 0)Red
(0, 0, 255)Blue
(255, 255, 0)Yellow

RGB is additive mixing of light. Combining red and green light gives yellow. A prediction based on mixing paint uses a different process and gives the wrong model for a screen.

Read hex color codes

A web color uses #RRGGBB: two hex digits for red, then green, then blue. #FF8000 means (255, 128, 0), an orange. #808080 means (128, 128, 128), a mid gray; equal channel values produce a gray. #0000FF gives the largest blue value with red and green at zero.

Each pair is one byte. Thus FF is 255, not a pair of separate color intensities. The # marks the whole RGB code and does not occupy a channel.

The RGB and palette models answer the pixel lookup differently. For direct RGB, reading the pixel gives its three channel intensities immediately. For indexed color, reading the pixel gives an entry number, and a second lookup supplies the intensities. Changing a palette entry can therefore change many displayed pixels that share the same index, even while their stored pixel indexes remain unchanged.

Store a palette index

When an image uses few colors, it can keep a palette, a table of the selected colors. A pixel then stores an index into that table. A 16-color palette needs four bits per pixel because four bits distinguish 16 entries. The palette itself also takes storage. GIF uses up to 256 palette colors, allowing an 8-bit index per pixel.

Add transparency

An alpha channel describes opacity. A common 8-bit scale uses 0 for fully transparent and 255 for fully opaque, with intermediate values for partial transparency. Adding that channel to 24-bit RGB gives 32-bit RGBA. Alpha is separate from red, green, and blue: a fully transparent pixel can still have stored color values that do not show in the final image.

Key Takeaways

  • A bitmap stores a grid of pixel values.
  • Color depth sets the number of color codes available per pixel.
  • Ordinary RGB uses three 8-bit channels, totaling 24 bits.
  • A palette index selects a color from a table.
  • An alpha channel adds opacity information; 8-bit alpha makes RGB into 32-bit RGBA.

5.2 Calculate image and video storage

An uncompressed bitmap's pixel data grows with its pixel count and its bits per pixel. Keeping the units attached to each step helps separate the amount of information from the byte size reported by a file viewer.

Calculate pixel data

Use bits=width×height×bits per pixel. Divide by 8 for bytes. Width and height must be multiplied because every row contains a full width of pixels.

For 1920 by 1080 at 24 bits per pixel, first find 2,073,600 pixels. Multiply by 24 to get 49,766,400 bits, then divide by 8 to obtain 6,220,800 bytes. That is about 6.2 MB, or 5.93 MiB. Changing the unit does not change the underlying pixel data.

For 640 by 480 at 8-bit grayscale, there are 307,200 pixels. Eight bits each give 2,457,600 bits; dividing by 8 gives 307,200 bytes, about 307 kB. Here one byte per pixel makes the final byte count equal to the pixel count.

Predict changes before calculating

Doubling the width doubles the pixels in each row. Doubling the height doubles the rows. Doubling both therefore multiplies the pixel count and storage by four. Raising depth from 8 to 24 bits per pixel triples storage at the same resolution. These factors multiply if both change.

The raw calculation gives pixel data, not necessarily a complete image file. A file also stores metadata, such as width, height, color depth, and format. A photo may record camera settings, date, and location. Palette tables, headers, padding, and compression can also change the final byte size.

For depths below eight bits, calculate the whole payload in bits before converting. A 100 by 60 one-bit image contains 6,000 pixel bits, or 750 packed bytes. Treating each pixel as a byte would overstate that payload eightfold. If a format pads each row to a particular boundary, its padding must be added separately; it is not a change in the color depth.

Extend the calculation to video

A video presents a sequence of images called frames. At 30 frames per second, 1920 by 1080 RGB video needs 6,220,800×30=186,624,000 bytes of uncompressed picture data each second, about 187 MB/s. Multiplying by duration gives the total picture data. Sound adds its own storage.

This large rate explains why ordinary video files are compressed. The rate of a compressed video is a separate quantity; it cannot be inferred from resolution alone.

Compare raster and vector images
BitmapVector
Stores a grid of color valuesStores shapes and drawing instructions
Suits photographs and textureSuits logos, diagrams, and font outlines
Enlarging the grid reveals pixelsShapes can be redrawn at a larger scale

A vector file can describe a line from (0, 0) to (100, 50), or a circle by its center, radius, and fill. It need not store a separate color value for every point inside the circle. Simple drawings can therefore be small. SVG is a common vector format.

A display still needs pixels. Rasterization turns the shapes into a pixel grid at the requested size. Scaling vector instructions preserves the shape's geometry; enlarging an existing bitmap cannot recover image detail that its original grid never recorded.

Key Takeaways

  • Uncompressed bitmap bits equal width × height × bits per pixel.
  • Divide bits by 8 before reporting bytes.
  • Doubling both dimensions quadruples pixel data at the same depth.
  • Raw video picture data equals bytes per frame × frame rate × duration.
  • Metadata and compression make file size differ from a raw pixel calculation.
  • Vector graphics store shapes that are rasterized for display.

5.3 Sample sound and calculate audio size

Sound is a vibration of air pressure. A microphone turns it into an analog electrical signal that varies continuously. An analog-to-digital converter takes regular measurements, called samples, and stores each one as a number.

Separate timing from measurement detail

The sample rate, measured in hertz, is the number of samples taken each second per channel. A rate of 44,100 Hz is 44.1 kHz. CDs use 44.1 kHz, video soundtracks commonly use 48 kHz, and traditional telephone audio uses 8 kHz. Samples record values at those instants; they are not a continuous record of every instant between them.

The bit depth sets how many levels each sample can use. Eight bits give 256 levels, 16 give 65,536, and 24 give 16,777,216. Rounding a measurement to a level is quantization. The difference from the original measurement produces quantization error, which can be heard as noise. More bits provide finer levels and reduce that error.

Sample rate controls detail in time; bit depth controls detail in measured amplitude. Increasing one does not replace increasing the other.

Capture the frequency range

The sampling theorem requires a sample rate greater than twice the highest frequency being captured. To capture 20 kHz, the rate must exceed 40 kHz. Exactly twice is insufficient for an arbitrary signal at the boundary.

At 44.1 kHz, the theoretical limit is below 22.05 kHz. The gap above about 20 kHz, the approximate upper limit of human hearing, gives room for an anti-aliasing filter. Frequencies above half the sample rate can appear as false lower frequencies, called aliasing. A converter filters those high frequencies before sampling.

A rate of 44,100 Hz applies to each channel, not to the recording as a combined stream. Stereo therefore stores 88,200 sample values each second. The channel factor belongs in the storage formula because each instant has a left value and a right value. It does not double the highest frequency each channel can capture; that limit still follows from its own sampling rate.

Calculate uncompressed audio

Mono has one channel; stereo has two. The payload size is

bits=sample rate×bit depth×channels×seconds

For a three-minute stereo recording at 44,100 Hz and 16 bits, the rate is 44,100×16×2=1,411,200 bit/s. Multiply by 180 seconds to obtain 254,016,000 bits, then divide by 8: 31,752,000 bytes, about 31.8 MB.

A ten-second mono recording at 8,000 Hz and 8 bits gives 8,000×8×1×10=640,000 bits, or 80,000 bytes. A stereo recording at the same settings would use twice as much.

Choose what to store

Higher rates and depths require more space. CD settings are generally enough for listening; studios often use 24 bits and 48 kHz or higher to leave room for processing and editing.

MIDI records note instructions: which notes, when they begin, their strength, and instrument choices. It can be much smaller than a sampled performance, but playback depends on the instrument sounds available. MIDI can describe a singer's melody as notes; it cannot contain the actual recorded voice.

Key Takeaways

  • Sample rate counts measurements per second; bit depth counts bits per measurement.
  • Quantization rounds a sample to one of the available levels.
  • The sample rate must exceed twice the highest frequency being captured.
  • Anti-aliasing filters remove high frequencies before sampling.
  • Audio bits equal sample rate × bit depth × channels × seconds.
  • MIDI stores performance instructions, not a recorded waveform.
6

Compress data and choose a format

Compression reduces the bits needed to store or send data. Some methods replace repeated information with shorter descriptions that can be reversed exactly. Others remove detail from pictures and sound to achieve smaller files. You will follow simple codes, account for the information a decoder needs, and choose a format by what must survive. A file intended for editing or exact recovery has different needs from a final stream for listening or viewing.

6.1 Lossless codes and their limits

Lossless compression lets decompression rebuild the original bits exactly. Text, program files, spreadsheets, and other exact data need that property. ZIP, PNG, GIF, and FLAC are familiar lossless formats. They exploit redundancy: repeated or predictable information that has a shorter description.

Describe repeated runs

Run-length encoding, or RLE, replaces consecutive identical symbols with a count and the symbol. The 18-character string "AAAAAABBBCCCCCCCCD" becomes "6A3B8C1D", eight characters under this count-and-symbol convention. Decoding expands each pair: six As, three Bs, eight Cs, and one D.

The same idea suits flat-color image regions. The pixel row 0000000011110000 can be described as eight zeros, four ones, and four zeros. A real file must define how counts and symbols are stored so that decoding is unambiguous.

Short runs can make RLE larger. "ABCD" becomes "1A1B1C1D", doubling the character count before any header. Compression works only when the savings exceed the cost of describing the pattern.

Refer to a repeated sequence

A dictionary method replaces a repeated sequence with a reference. LZ-family methods underlie formats such as ZIP and PNG. In "to be or not to be", the second "to be" can be replaced by an instruction to go back 13 characters and copy five. Spaces count as characters. The decoder already has that earlier text and can reproduce the sequence from the reference.

Give common symbols shorter codes

A variable-length code uses different bit lengths for different symbols. Huffman coding builds codes from symbol frequencies. For "ABRACADABRA", A appears five times, B and R twice each, and C and D once each. A fixed-width code for five symbols needs three bits per symbol, or 33 bits for eleven letters.

One suitable prefix-free code is A = 0, B = 10, R = 110, C = 1110, and D = 1111. The encoded data uses 5×1+2×2+2×3+1×4+1×4=23 bits. The code table adds overhead, so 23 bits alone is not the complete file size.

Prefix-free means no symbol's code begins another symbol's code. Reading 0110 therefore gives A followed by R without needing separators. This property lets a Huffman decoder recognize a symbol as soon as its code ends.

The decoder must know the coding convention as well as the payload. For a Huffman-style stream, it needs the symbol-to-code mapping; for RLE, it needs to distinguish a count from a symbol. A small message may save payload bits yet grow overall when this description is included. Compare complete original and encoded sizes when deciding whether a method actually reduced the file.

Measure savings and recognize limits

The compression ratio is original size divided by compressed size. Reducing 6 MB to 2 MB gives 3:1. Use the same unit on both sides.

No lossless method can shorten every possible file. There are 2n different n-bit inputs but only 2n−1 bit strings shorter than n bits. Exact recovery requires different inputs to remain distinguishable, so they cannot all receive shorter outputs. Random data and already compressed files often shrink little or grow because of added overhead.

Key Takeaways

  • Lossless decompression reproduces the original bits exactly.
  • RLE describes identical consecutive symbols with counts.
  • Dictionary methods replace repeated sequences with references.
  • Huffman coding assigns shorter codes using symbol frequencies.
  • A prefix-free code identifies symbol boundaries without separators.
  • Compression ratio compares original size with compressed size.
  • No lossless method shortens every possible input.

6.2 Lossy formats and quality choices

Lossy compression removes information to reduce file size. Decompression creates a close version of the original, with some detail permanently missing. Photographs, music, speech, and video can tolerate selected losses that exact text or program data cannot.

Compress pictures by visual importance

JPEG relies on human vision's different sensitivity to brightness, color, and fine detail. A typical JPEG reduces fine color resolution and rounds fine image detail represented in 8 by 8 blocks. Its quality setting controls how strongly information is discarded. Stronger compression can produce blockiness or blur and ringing near sharp edges.

A photograph can often reach about 10:1 with little visible loss. At that ratio, an image with 6,220,800 bytes of raw pixel data would use about 622,080 compressed bytes, roughly 0.6 MB. The ratio is an example, not a fixed property of every JPEG.

Compress sound by what can be heard

MP3 and AAC use perceptual coding. A quiet sound can be masked by a louder sound at a nearby frequency, so the encoder can devote fewer bits to information a listener is unlikely to hear. A smaller file can still sound very close to the original.

For a constant bit rate, size in bits equals bit rate times duration. At 128 kbit/s, a three-minute recording needs 128,000×180=23,040,000 bits, or 2,880,000 bytes, about 2.9 MB. That is about one eleventh of the 1,411.2 kbit/s of uncompressed CD audio. The compressed rate already describes the encoded stream; do not multiply it by the original sample depth again.

Exploit similarities across video frames

Neighboring frames often show nearly the same scene. Video formats such as H.264 and AV1 compress image detail and describe many frames through changes or predictions from other frames. This removes repeated information across time as well as within each picture.

Match the format to the use
UseSuitable choiceReason
Exact text, code, or dataLossless archiveEvery bit must survive
Photo for sharingJPEG or another lossy image formatSmall size with acceptable visual loss
Screenshot or logoPNGPreserves sharp edges and flat colors
Music for streamingAAC, MP3, or OpusSaves transfer capacity
Audio master for archivingFLACExact recovery of the audio samples

Keep a lossless original for future editing. Repeated lossy decoding and re-encoding can add generation loss. Converting an already lossy JPEG to PNG preserves its current decoded pixels but cannot restore detail removed earlier.

Greater compression can cost quality, processing time, or both. The useful choice depends on what a file contains and how it will be used; the smallest file is not always the most useful one.

Key Takeaways

  • Lossy compression permanently removes selected information.
  • JPEG exploits visual sensitivity; lossy audio uses perceptual coding.
  • Compressed-stream size follows bit rate × duration.
  • Keep a lossless original when future editing or exact recovery matters.
  • Changing a lossy file to a lossless format cannot recover discarded information.

Binary and Data Representation examples

6 Walkthroughs

1

Build a code, then read its bits

12 steps
Count the patterns a field needs, convert its values, and connect binary groups to hex notation.
  1. 1
    IntroductionOne pattern, several readings

    A stored pattern has two separate features: how many bits it occupies and how a reader interprets them. The eight bits 01000001 could mean a number, a text character, or a color intensity.

    We will first choose enough bits to distinguish a collection of values, then read a numerical pattern using binary place values and hexadecimal. Changing the notation changes what you write, while keeping the value intact.

  2. 2
    ExplanationCount choices by doubling

    Each bit has two choices, so each added bit doubles the number of patterns. Two bits give 00, 01, 10, and 11; three bits give eight patterns. In general, n bits give 2n patterns.

    To identify 26 letters, four bits fail because they give only 16 patterns. Five bits give 32 and leave six patterns unused. A code does not have to use every available pattern.

  3. 3
    ChallengeChoose a field for categories

    A device must distinguish 90 categories. What is the smallest bit count that can encode them? How many patterns will remain unused?

    ---reveal---

    Six bits give 64 patterns, too few. Seven give 128, so the field needs seven bits and leaves 38 patterns unused. The largest numeric label could be 89 if labels start at zero; that endpoint is different from the 90-category count.

  4. 4
    ConnectionRead the case of the unit letter

    A byte has eight bits. That makes the case of the unit letter matter: b means bit and B means byte. A 40 Mbit/s link has an ideal payload ceiling of 5 MB/s before overhead.

    Unit prefixes matter separately. One MB means one million bytes, while one MiB means 1,048,576 bytes. Converting a stored amount from MB to MiB changes the numerical reading without removing any data.

  5. 5
    ExplanationLine up binary places

    The rightmost whole-number place is 1. Moving left gives 2, 4, 8, 16, 32, 64, and so on. A 1 selects a place and a 0 leaves it out.

    For 101101, the selected places are 32, 8, 4, and 1, totaling 45. Leading zeros can fill a width without changing these places. A missing zero inside the pattern would shift some of the digits and change the value.

  6. 6
    ExampleSelect the powers for 156

    The largest power of two not exceeding 156 is 128. Subtract it to leave 28. The 64 and 32 places do not fit, so give them zeros.

    Take 16 from 28, leaving 12. Take 8, leaving 4, then take 4 to reach zero. The final two places, 2 and 1, receive zeros. Across the places 128 through 1, the bits are 10011100. Keeping every unused place prevents the chosen powers from shifting.

  7. 7
    TipReverse whole-number remainders

    Repeated division is another route to the same pattern. Dividing a whole number by two gives its last bit as the remainder. Dividing the quotient finds the next bit to the left.

    For 156, the remainders arrive as 0, 0, 1, 1, 1, 0, 0, 1. Read from last to first to obtain 10011100. The reverse order is necessary because division discovers the least significant place first.

  8. 8
    ChallengeConvert and check a new value

    Write decimal 109 in eight binary places, then use your result to explain whether 109 is odd.

    ---reveal---

    The chosen powers are 64, 32, 8, 4, and 1, so the pattern is 01101101. Their sum is 109, which checks the conversion. The last bit is 1; all the other places contribute even quantities, leaving an odd whole number. The leading zero fills the byte without changing the value.

  9. 9
    ExplanationReplace nibbles with hex digits

    Hex has sixteen digits: 0–9 followed by A–F for ten through fifteen. Four bits also distinguish sixteen patterns, so each hex digit names one nibble.

    Split 10011100 into 1001 and 1100. The first group is nine and the second is twelve, written C. The result is 0x9C. Hex is four times shorter than binary in digit count, while keeping a direct link to groups inside the byte.

  10. 10
    ExampleGroup a short pattern from the right

    To convert 101101, form groups from the right: 10 and 1101. Pad the far-left group to 0010. The groups now give hex 2 and D, so the value is 0x2D.

    Check using hex place values: two sixteens plus thirteen ones gives 45. Grouping from the left would put the final short group in the wrong place. Inside a full hex expansion, each digit must retain all four bits.

  11. 11
    ChallengeConnect bits, width, and hex

    A fixed-width unsigned field stores 0xB4. How many bits are shown by its two hex digits, what is its binary pattern, and what decimal value does it hold?

    ---reveal---

    Two hex digits represent eight bits. B expands to 1011 and 4 to 0100, so the byte is 10110100. Its selected places sum to 128 + 32 + 16 + 4 = 180. Equivalently, eleven sixteens plus four gives 180.

  12. 12
    RecapThree checks for a stored value

    Check capacity, notation, and units separately. A field needs enough patterns for all its possible values. Binary selects powers of two; hex groups those bits into fours from the right.

    The stored value survives a change of written base or storage unit. A changed data interpretation can give the same bits a different meaning, so the pattern and the rule for reading it belong together.

2

Read signed values and preserve their width

11 steps
Work with unsigned limits, two’s complement encoding, and widening a negative value.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionA width needs an interpretation
  2. 2
    ExplanationReserve a pattern for zero
  3. 3
    ExampleFollow unsigned wraparound
  4. 4
    ChallengeChoose enough room for a count
  5. 5
    ExplanationGive the leading bit a negative weight
  6. 6
    ExampleStart the pattern for −45
  7. 7
    ExampleComplete the negation
  8. 8
    ChallengeEncode another negative integer
  9. 9
    Key InsightExtend the sign, not just the zeros
  10. 10
    ChallengeWiden before taking the opposite
  11. 11
    RecapKeep the rule with the pattern
3

Build a floating-point encoding

17 steps
Convert a binary fraction, assemble IEEE 754 fields, and reason about rounding and spacing.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionA value and a scale
  2. 2
    ExplanationRead the fraction places
  3. 3
    ExampleGenerate a terminating fraction
  4. 4
    Key InsightPredict whether the digits end
  5. 5
    ChallengeFind the scale in fixed point
  6. 6
    ExplanationRecognize the fields
  7. 7
    ExampleWrite 6.25 in binary
  8. 8
    ExampleEncode the exponent
  9. 9
    ExampleStore only the fraction
  10. 10
    ExampleJoin the three fields
  11. 11
    ChallengeDecode a different normal value
  12. 12
    TipClassify reserved patterns first
  13. 13
    ExplanationSeparate range from spacing
  14. 14
    Key InsightWatch the gap grow
  15. 15
    ChallengeRound a halfway integer
  16. 16
    ChallengeChoose a type for an exact amount
  17. 17
    RecapRead the format before the value
4

Follow text from characters to bytes

12 steps
Distinguish ASCII codes, Unicode code points, and encoded bytes, then diagnose a decoding mismatch.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionText needs an agreement
  2. 2
    ExplanationFind the ASCII character code
  3. 3
    ExampleEncode letters and punctuation
  4. 4
    ChallengeRecover a numeric digit
  5. 5
    ConnectionWhy a single byte was not enough
  6. 6
    ExplanationIdentify before encoding
  7. 7
    ExampleSplit the bits for é
  8. 8
    ExampleFinish the two encoded bytes
  9. 9
    ChallengeCount a mixed-script string
  10. 10
    Key InsightOne appearance can have two forms
  11. 11
    ChallengeDiagnose the garbled word
  12. 12
    RecapKeep three counts separate
5

Budget storage for pictures and recordings

15 steps
Use pixel and sample counts, separate bit depth from resolution, and compare raw storage with instruction-based formats.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionCount values, then bits per value
  2. 2
    ExplanationBuild an RGB pixel
  3. 3
    ConnectionAdd transparency or use a palette
  4. 4
    ChallengeRead a color and its depth
  5. 5
    ExampleStart with the pixel grid
  6. 6
    ExampleConvert the picture to bytes
  7. 7
    ChallengeScale the grid and add frames
  8. 8
    Key InsightA drawing can store instructions
  9. 9
    ExplanationSample timing and amplitude separately
  10. 10
    ExplanationFilter before sampling
  11. 11
    ExampleFind the audio rate first
  12. 12
    ChallengeCalculate a different recording
  13. 13
    ConnectionNotes can replace a waveform
  14. 14
    ChallengeCompare two storage changes
  15. 15
    RecapKeep the factors and units visible
6

Compress without confusing size and fidelity

12 steps
Apply run-length and variable-length codes, account for overhead, and decide when information may be discarded.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionTwo ways to get a smaller file
  2. 2
    ExplanationReplace runs with counts
  3. 3
    ChallengeTry long runs and short runs
  4. 4
    ConnectionPoint to a sequence already seen
  5. 5
    ExampleGive frequent symbols short codes
  6. 6
    ChallengeDecode the stream in order
  7. 7
    Key InsightSome inputs must stay large
  8. 8
    ExplanationRemove less noticeable media detail
  9. 9
    ExampleUse a compressed bit rate directly
  10. 10
    ChallengeProtect a master while sharing a copy
  11. 11
    ChallengeCompare a ratio with a transfer budget
  12. 12
    RecapMatch the guarantee to the purpose

Binary and Data Representation practice questions

50 Practice Questions in 5 sets

Set 1: Apply formats and calculate payloads10 Practice Questions

Question 1 of 10

A positive value is finite in binary64 but overflows binary32 under default rounding. What aspect of binary32 has been exceeded?
  1. Its integer count
  2. Its decimal places
  3. Its finite range
  4. Its text format
Show answerHide answer
Answer: C
Overflow means the magnitude is too large for the format’s finite range. Precision concerns the spacing of values that can be represented within that range. A number can need rounding while still remaining finite, so loss of exactness alone does not establish overflow.

Question 2 of 10

What is the UTF-8 byte count of "AЖ中😀" if Ж is U+0416, 中 is U+4E2D, and 😀 is U+1F600?
  1. 10 bytes
  2. 4 bytes
  3. 8 bytes
  4. 12 bytes
Show answerHide answer
Answer: A
The ASCII letter uses one byte, U+0416 uses two, U+4E2D uses three, and U+1F600 uses four. Adding them gives ten bytes. Counting four visible characters as four bytes assumes that every character is ASCII, which these code points rule out.

Question 3 of 10

A bitmap uses a palette of exactly 32 colors. What is the smallest fixed number of bits needed for each pixel index?
  1. 4 bits
  2. 6 bits
  3. 32 bits
  4. 5 bits
Show answerHide answer
Answer: D
Five bits give 32 distinct patterns, one for each palette entry. Four bits give only 16 and cannot select every color. The index size is separate from the bytes used to store the palette’s actual color values in the file.

Question 4 of 10

An uncompressed 300 × 200 RGB image uses 24 bits per pixel. Both dimensions are doubled and an 8-bit alpha channel is added. What is the new pixel-data size?
  1. 720,000 bytes
  2. 960,000 bytes
  3. 480,000 bytes
  4. 240,000 bytes
Show answerHide answer
Answer: B
The new grid is 600 × 400 = 240,000 pixels, each now using 32 bits, or four bytes. That gives 960,000 bytes. The value 720,000 correctly enlarges the grid but keeps three bytes per pixel, overlooking the added alpha channel.

Question 5 of 10

How is −19 represented in 8-bit two's complement?
  1. 11101101
  2. 11101100
  3. 10010011
  4. 00010011
Show answerHide answer
Answer: A
Positive 19 is 00010011; inverting gives 11101100, and adding one gives 11101101. The pattern 11101100 stops after inversion and represents −20. Setting only the sign bit would use sign-magnitude and would not encode −19 in two’s complement.

Question 6 of 10

A normal binary32 value has sign 0, stored exponent 125, and fraction bits 100 followed by zeros. What is its decimal value?
  1. 1.5
  2. 0.25
  3. 0.375
  4. 0.1875
Show answerHide answer
Answer: C
Subtract the bias: 125 − 127 = −2. Restoring the hidden 1 gives a significand of 1.5, so the value is 1.5 × 2⁻² = 0.375. The result 0.25 drops the nonzero fraction bits and treats the significand as exactly 1.

Question 7 of 10

A link transfers at 48 Mbit/s. Ignoring overhead, how many decimal megabytes can it transfer in 5 seconds?
  1. 6 MB
  2. 30 MB
  3. 240 MB
  4. 3 MB
Show answerHide answer
Answer: B
The link transfers 48 × 5 = 240 million bits in five seconds. Dividing by eight gives 30 million bytes, or 30 MB. The value 6 MB is the amount transferred in one second, so it omits the stated duration.

Question 8 of 10

What is 74 written as an 8-bit unsigned binary value?
  1. 01010010
  2. 10010100
  3. 01001001
  4. 01001010
Show answerHide answer
Answer: D
The selected places are 64, 8, and 2, totaling 74. Their bits give 01001010 when padded to eight places. The pattern 01010010 instead selects 64, 16, and 2, totaling 82, because it moves the 8 contribution to the 16 place.

Question 9 of 10

A mono recording lasts 4 seconds at 30,000 Hz with 12-bit samples. After low-pass filtering, its highest frequency is 14 kHz. What raw payload size and sampling verdict follow?
  1. 180,000 bytes; rate is insufficient
  2. 180,000 bytes; rate is sufficient
  3. 360,000 bytes; rate is sufficient
  4. 120,000 bytes; rate is insufficient
Show answerHide answer
Answer: B
The payload is 30,000 × 12 × 4 ÷ 8 = 180,000 bytes. The rate is sufficient because 30 kHz exceeds twice 14 kHz. A rate exactly equal to 28 kHz would fail the strict boundary, but the stated rate is above it; two channels would double the payload, while this is mono.

Question 10 of 10

A constant-rate audio stream uses 96 kbit/s for 50 seconds. Ignoring headers, what is its size in decimal bytes?
  1. 600,000 bytes
  2. 4,800,000 bytes
  3. 6,000,000 bytes
  4. 300,000 bytes
Show answerHide answer
Answer: A
Multiply 96,000 bits per second by 50 seconds to obtain 4,800,000 bits. Dividing by 8 gives 600,000 bytes. Keeping 4,800,000 as the byte count misses the bit-to-byte conversion; the stated bit rate already includes the encoded audio stream.
Set 2: Read patterns and estimate storage10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A status field must distinguish 70 different states. What is the smallest number of bits it needs?
  1. 6 bits
  2. 8 bits
  3. 7 bits
  4. 70 bits
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

What decimal value does the binary number 1010110 represent?
  1. 86
  2. 84
  3. 106
  4. 43
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

How is the binary whole number 1110101 written in hexadecimal?
  1. 0xE5
  2. 0x7A
  3. 0xD1
  4. 0x75
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

What is the largest unsigned integer that fits in 12 bits?
  1. 4,096
  2. 4,095
  3. 2,047
  4. 4,097
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

What value does 11101010 represent as an 8-bit two's complement integer?
  1. −106
  2. −22
  3. 234
  4. −21
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

What decimal value is represented by the binary fraction 10.011?
  1. 2.75
  2. 2.3
  3. 2.625
  4. 2.375
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

In ASCII, "0" has code 48. What is the code for the character "8"?
  1. 56
  2. 8
  3. 55
  4. 64
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

What RGB channel values does the web color #4080C0 specify?
  1. (40, 80, 120)
  2. (192, 128, 64)
  3. (64, 128, 192)
  4. (4, 8, 12)
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

How many bytes of uncompressed sample data are needed for 6 seconds of 12,000 Hz, 16-bit mono audio?
  1. 72,000 bytes
  2. 288,000 bytes
  3. 1,152,000 bytes
  4. 144,000 bytes
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A lossless code uses A = 0, B = 10, C = 110, and D = 111. A message has 40 As, 5 Bs, 2 Cs, and 1 D. A required table adds 16 bits. How many bits are saved against a fixed 2-bit code with no table?
  1. 21 bits
  2. 37 bits
  3. 16 bits
  4. 5 bits
Show answerHide answer

Save this lesson to see this answer.

Set 3: Interpret the same bits in different ways10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

What decimal value does 0x2B6 represent?
  1. 678
  2. 710
  3. 438
  4. 694
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

An 8-bit unsigned counter uses wraparound. It starts at 247 and increases by 28. What value is stored?
  1. 19
  2. 20
  3. 255
  4. 275
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A 6-bit two's complement field contains 101101. It is widened to 8 bits without changing its value. What are the widened pattern and decimal value?
  1. 00101101; −19
  2. 11101101; −45
  3. 11101101; −19
  4. 10101101; −19
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

What is the step between adjacent values when an unsigned fixed-point format has six fraction bits?
  1. 1/6
  2. 1/64
  3. 1/32
  4. 1/128
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

What are the sign, stored exponent, and start of the fraction field when −13.5 is encoded as normal binary32?
  1. 1; 130; 11011…
  2. 1; 130; 1011…
  3. 1; 124; 1011…
  4. 1; 131; 1011…
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

The text "0064" is stored as one ASCII byte per character. How many bytes does it occupy?
  1. 4 bytes
  2. 1 byte
  3. 2 bytes
  4. 8 bytes
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

The bytes for "é" in UTF-8 are C3 A9. A reader interprets them as two Windows-1252 characters. What is the direct cause of the garbled display?
  1. The writer used too few code points.
  2. The text exceeded one byte per file.
  3. The reader used the wrong encoding.
  4. The reader changed the Unicode number.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A bitmap’s width is tripled and height is doubled while color depth stays fixed. By what factor does its raw pixel-data size grow?
  1. 5
  2. 3
  3. 12
  4. 6
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A prefix-free code is A = 0, B = 10, C = 110, D = 111. What message is encoded by 1011001110?
  1. BCDAA
  2. BACDA
  3. BCADA
  4. CBADA
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A photographer converts an existing JPEG to PNG without changing its decoded pixels. What happens to detail previously discarded by JPEG?
  1. It returns when PNG is reopened.
  2. It returns if the PNG is larger.
  3. It returns as new metadata fields.
  4. It remains missing from the image.
Show answerHide answer

Save this lesson to see this answer.

Set 4: Diagnose errors and connect representations10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A learner divides 90 by 2 repeatedly and writes the remainders in the order obtained as 0101101. What is the correct binary value of 90?
  1. 0101101
  2. 1010110
  3. 1011010
  4. 1101010
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

A file viewer shows the three bytes 0x07, 0xB2, and 0xF0. How many bits do those bytes contain?
  1. 12 bits
  2. 6 bits
  3. 48 bits
  4. 24 bits
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A sensor records integer counts from 0 through 8,192 inclusive. Each count uses the smallest possible unsigned width and fields are packed without padding. How many bytes hold 40 counts?
  1. 65 bytes
  2. 70 bytes
  3. 80 bytes
  4. 560 bytes
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A file has 3,145,728 bytes. What is its size in MiB?
  1. 3 MiB
  2. 3.145728 MiB
  3. 3,072 MiB
  4. 24 MiB
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A binary32 pattern has sign 1, an all-one exponent, and a nonzero fraction. What is its category, and can changing only the sign bit make it a finite number?
  1. Infinity; a sign flip keeps it infinite
  2. Subnormal; a sign flip makes it normal
  3. Finite; a sign flip keeps it finite
  4. NaN; changing the sign keeps it NaN
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

Two adjacent positive normal binary32 values in the interval from 2²⁵ to 2²⁶ differ by 4. What does default rounding do to the exact integer 33,554,435?
  1. It stores 33,554,432.
  2. It stores 33,554,435 exactly.
  3. It stores 33,554,436.
  4. It overflows to positive infinity.
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A storage limit allows 18 UTF-8 bytes. A string contains only the character "中" (U+4E2D), with no other data counted. How many copies fit?
  1. 6
  2. 18
  3. 9
  4. 4
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A 20 × 10 image uses 16 palette entries, each stored as 24-bit RGB, and packed 4-bit pixel indexes. Ignoring everything else, how many bytes are needed?
  1. 100 bytes
  2. 148 bytes
  3. 600 bytes
  4. 196 bytes
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A filtered signal contains frequencies up to 17 kHz. What is the smallest whole-number sample rate in kHz that meets the strict sampling rule?
  1. 17 kHz
  2. 35 kHz
  3. 34 kHz
  4. 33 kHz
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A decoder must recover every possible 10-bit input exactly. There are 1,024 such inputs. Why can a lossless scheme not encode them all in fewer than 10 bits?
  1. Only 1,023 bit strings are shorter than 10 bits.
  2. Exactly 1,024 bit strings are shorter than 10 bits.
  3. Every shorter bit string must end in a 1 bit.
  4. Every input must keep its original bit positions.
Show answerHide answer

Save this lesson to see this answer.

Set 5: Combine limits, encodings, and size choices10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A recorder keeps 16-bit stereo samples at 24 kHz. It must capture a filtered signal whose highest frequency is 10 kHz and stay within 6,000,000 bytes of raw sample data. What is the longest whole-number duration in seconds?
  1. 63 seconds
  2. 125 seconds
  3. 31 seconds
  4. 62 seconds
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

An uncompressed silent clip has 160 × 120 pixels, 24 bits per pixel, and 25 frames/s. Ignoring headers, how many complete seconds fit in 7.2 MB of decimal storage?
  1. 4 seconds
  2. 10 seconds
  3. 5 seconds
  4. 40 seconds
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A recording keeps its sample rate and duration but changes from 16-bit stereo to 24-bit mono. What fraction of the original raw sample-data size remains?
  1. 3/4
  2. 3/2
  3. 1/2
  4. 4/3
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A text field contains "09" as ASCII bytes 0x30 0x39. What numeric value results from interpreting these characters as a decimal integer?
  1. 57
  2. 9
  3. 3,039
  4. 48
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A binary whole number is written as 110011. What decimal value results when a zero is appended to its right, with unlimited width?
  1. 51
  2. 52
  3. 102
  4. 204
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

What is the smallest value of a 10-bit two's complement integer?
  1. −511
  2. −512
  3. −1,024
  4. −1,023
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

An unsigned 8-bit fixed-point format has five whole-number bits and three fraction bits. A value of 6.375 is stored exactly. What unsigned integer does the raw 8-bit pattern represent when the fixed-point scale is ignored?
  1. 51
  2. 6
  3. 48
  4. 102
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

An 8-bit two's complement value is 10000000. It is sign-extended to 16 bits and then negated in 16 bits. What pattern results?
  1. 1111111110000000
  2. 0000000001111111
  3. 1000000000000000
  4. 0000000010000000
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

In binary32, adjacent representable values near 2²⁴ are 16,777,216 and 16,777,218. What is the stored result of converting the exact integer 16,777,217 under nearest, ties-to-even rounding?
  1. 16,777,216
  2. 16,777,217
  3. 16,777,218
  4. 16,777,220
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A project needs exact recovery of an edited audio master and a 90-second delivery copy no larger than 1.8 MB of encoded payload. What pair of choices meets both needs?
  1. MP3 master; constant 160 kbit/s delivery
  2. FLAC master; constant 192 kbit/s delivery
  3. FLAC master; constant 160 kbit/s delivery
  4. AAC master; constant 128 kbit/s delivery
Show answerHide answer

Save this lesson to see this answer.

Stuck on your own question? Homework Help

Key Terms

81 Key Terms, each with its definition

A

Aliasing
Aliasing occurs when sampled frequencies above half the sample rate appear as false lower frequencies in the digital recording.
An anti-aliasing filter removes high input frequencies before sampling so they do not create false tones.
Alpha channel
An alpha channel stores a pixel’s opacity separately from its color, commonly using 0 for transparent and 255 for opaque.
An RGBA pixel uses four eight-bit values, so its raw storage is four bytes instead of RGB’s three.
Analog signal
An analog signal varies continuously, such as a microphone voltage that follows changes in air pressure produced by sound.
An audio converter measures a microphone’s analog signal before storing digital samples of it.
ASCII
ASCII is a seven-bit character code with 128 entries for English letters, digits, punctuation, space, and control characters.
The exclamation mark has ASCII code 33 and is commonly stored as the byte 00100001.
Audio bit depth
Audio bit depth is the number of bits used per sample, setting the number of available amplitude levels and their fineness.
Sixteen bits allow 65,536 sample levels, while eight bits allow only 256 and coarser quantization.

B

Base
A number system’s base sets the number of digit values and the factor between neighboring whole-number place values.
A written "10" means two in base 2, ten in base 10, and sixteen in base 16.
Binary
Binary is the base-2 number system, using the digits 0 and 1 with place values that are powers of two.
The binary whole number 10010 selects the sixteen and two places, so its decimal value is eighteen.
Binary point
The binary point separates whole-number powers of two from fractional powers, beginning with one half immediately to its right.
The first 1 after the point in 0.101₂ contributes one half, and the final 1 contributes one eighth.
Bit
A bit is a binary digit with one of two values, 0 or 1, represented by two physical states that hardware can distinguish.
A status flag can store an on/off choice in one bit, with a program defining which state means "on".
Bit rate
A bit rate is the number of encoded or transferred bits per second, commonly written in bit/s, kbit/s, or Mbit/s.
A transfer rate of 16 Mbit/s corresponds to 2 MB/s before any communication overhead is counted.
Bitmap
A bitmap, or raster image, represents a picture as a rectangular grid of pixel values, with a width, height, and color depth.
A digital photograph is stored as a bitmap because each part of its detailed image needs a pixel value.
Byte
A byte is a group of eight bits, giving 256 possible patterns and usually forming the smallest addressable unit of memory.
The byte 01000001 can represent the number 65 or the letter "A", depending on how it is interpreted.

C

Character code
A character code is the number assigned to a character by an agreed table, allowing text symbols to be stored as bit patterns.
The character "3" has ASCII code 51, although its numerical digit value is three.
Code page
A code page is a character-to-code mapping, often a legacy eight-bit table whose upper-byte meanings differ from other tables.
The byte 0xE9 gives "é" in Latin-1 and "й" in Windows-1251, so the reader must know the code page.
Code point
A code point is a numbered position in Unicode’s code space, written as U+ followed by hexadecimal digits, such as U+00E9.
The code point for "é" stays U+00E9 whether its bytes are stored using UTF-8, UTF-16, or UTF-32.
Color depth
Color depth is the number of bits used to represent one pixel’s color code, setting how many distinct color codes it can have.
A four-bit palette index can select among sixteen colors, while 24-bit RGB offers many more combinations.
Compression
Compression reduces storage or transfer needs by encoding data in fewer bits, with exact recovery depending on whether the method is lossless.
A smaller encoded image transfers faster over the same link because fewer bits must be sent.
Compression artifact
A compression artifact is an unwanted visible or audible change caused by approximations introduced during lossy encoding.
At a strong JPEG setting, a sharp letter edge can acquire blur or block-shaped changes in nearby pixels.
Compression ratio
The compression ratio is the original data size divided by its compressed size, with both quantities expressed in the same unit.
Reducing a file from 15 MB to 5 MB gives a compression ratio of 3:1, not a 3 MB saving.
Control character
A control character is a text code that directs text handling without printing an ordinary visible symbol, such as tab or line feed.
ASCII code 10 is a line feed, so a file can use it to mark a line break among the text bytes.

D

Data type
A data type specifies the kind of value a program handles and helps determine how its stored bit patterns are interpreted.
A byte interpreted as a signed integer can have a different value from the same byte interpreted as unsigned.
Dictionary method
A dictionary method compresses data by replacing repeated sequences with references to sequences known to or reconstructed by the decoder.
A repeated phrase can be represented by a distance back into decoded text and a length to copy.

E

Encoding
A character encoding specifies how valid character values become a sequence of code units or bytes for storage and transmission.
UTF-8 encodes "é" as C3 A9, while a code-point label identifies the character without giving that byte sequence.
Exponent bias
An exponent bias is a fixed offset added to the true exponent so that the stored exponent can be an unsigned bit field.
A binary32 stored exponent of 126 gives a true exponent of −1 after subtracting its bias of 127.

F

Finite binary expansion
A finite binary expansion ends after a limited number of binary places; a reduced fraction has one exactly when its denominator is a power of two.
The fraction 5/8 terminates as 0.101₂, while 1/10 needs a repeating sequence of binary digits.
Fixed point
Fixed point interprets stored bits with an agreed number of fractional places, producing evenly spaced values at a fixed scale.
With four fraction bits, a raw integer value of 40 represents 40/16, or 2.5, in unsigned fixed point.
Fixed width
A fixed width is a set number of bits reserved for each value, which limits how many distinct patterns can be stored.
An eight-bit counter cannot grow a ninth stored bit when a result reaches 256; its overflow rule matters.
Floating point
Floating point stores a sign, a significand, and a scale given by an exponent, covering widely different magnitudes in one format.
The same format can represent a small measured length and a much larger distance by changing its exponent.
Frame
A video frame is one image in a timed sequence; the frame rate gives how many such images are shown per second.
At 25 frames per second, one second of raw video contains twenty-five complete images before audio is counted.

G

Generation loss
Generation loss is the further loss of information that can accumulate when media is repeatedly decoded and encoded with a lossy method.
Saving an edited photo through repeated JPEG re-encoding can add losses even if each save looks similar.

H

Hex digit
A hex digit is one symbol from 0–9 or A–F that gives a value from zero through fifteen in a single base-16 place.
The hex digit E means fourteen, whereas the two-digit value 0x14 means twenty in decimal.
Hexadecimal
Hexadecimal is base 16, using digits 0–9 and A–F, with each digit corresponding to four binary bits.
The byte 11001010 is shorter to write as 0xCA, while retaining a clear digit for each nibble.
Hidden bit
The hidden bit is the leading 1 implied for a normal binary floating-point significand, gaining precision without a stored fraction bit.
Binary32 stores 23 fraction bits but has 24 significant bits for normal values because the leading 1 is implied.
Huffman coding
Huffman coding builds a prefix-free variable-length code from symbol frequencies, giving frequent symbols shorter codes to reduce payload size.
A frequent letter may receive a one-bit code, but the file also needs information that allows decoding.

I

IEC binary prefix
An IEC binary prefix scales a data unit by a power of 1,024, using names such as kibi, mebi, and gibi.
One MiB contains 1,048,576 bytes, so a one-million-byte file occupies slightly less than one MiB.
IEEE 754
IEEE 754 is the standard defining widely used floating-point formats and behavior, including normal values, rounding, and special values.
Binary32 and binary64 follow IEEE 754, so their field layouts can be decoded using a shared set of rules.
Image metadata
Image metadata describes a picture or its storage, including dimensions and depth, and can also include camera details, date, or location.
A photograph file can contain camera information even though those bytes are not part of the visible pixel grid.

L

Least significant bit
The least significant bit is the rightmost bit of a binary whole number, carrying the ones-place contribution.
The least significant bit of 10110 is 0, so the whole number is even regardless of its other bits.
Lossless compression
Lossless compression produces an encoding from which the original bits can be reconstructed exactly, including every text or sample value.
A FLAC archive can restore the audio samples exactly even though its stored byte count is smaller.
Lossy compression
Lossy compression permanently discards selected information, producing a smaller representation that reconstructs an approximation of the original.
A high-quality JPEG may look close to the photo while still being unable to reproduce its original pixels exactly.

M

MIDI
MIDI stores or communicates musical performance instructions, such as notes and timing, instead of the sound waveform of a recording.
A MIDI melody can be played with different instrument sounds, but it does not preserve a recorded singer’s voice.
Mojibake
Mojibake is garbled text produced when a reader decodes stored bytes using an encoding different from the one used to write them.
UTF-8 "café" can appear as "café" when its bytes are decoded as Windows-1252.
Most significant bit
The most significant bit is the leftmost bit of a written fixed-width pattern, carrying the highest-order place.
In an unsigned byte, changing the most significant bit changes the value by 128 while other bits stay fixed.

N

NaN
NaN, or "not a number", is a special floating-point category with an all-one exponent field and a nonzero fraction.
An invalid numerical operation such as zero divided by zero can produce NaN instead of an ordinary number.
Negation
Negation changes a number to its additive opposite; within two’s complement it is formed by inverting all bits and adding one.
Negating the eight-bit pattern for +6 gives the pattern for −6, while the minimum value has no positive counterpart.
Nibble
A nibble is a group of four bits, giving sixteen possible patterns and corresponding exactly to one hexadecimal digit.
The byte 10100111 splits into the nibbles 1010 and 0111, which are hex digits A and 7.
Normalization
Unicode normalization converts equivalent character sequences to a common form so that strings with different code-point sequences can be compared.
A precomposed accented letter and its base-plus-accent sequence can be normalized before string comparison.

O

Overflow
Overflow occurs when a calculated result lies outside the values that the chosen number format can represent.
For an unsigned eight-bit counter, a result of 260 is outside the 0–255 range and needs overflow handling.

P

Palette
A palette is a stored table of selected colors, allowing each pixel to name a table entry with a smaller index value.
A sixteen-color icon can use four-bit pixel indexes, while keeping its actual RGB colors in the palette.
Perceptual coding
Perceptual coding reduces media data according to human sensitivity, giving less space to details that people are unlikely to notice.
An audio encoder can remove a quiet tone masked by a louder nearby-frequency sound in an MP3 listening copy.
Pixel
A pixel is one position in a raster image’s grid, holding a color value or an index that selects a color from a palette.
A 400 × 300 bitmap contains 120,000 pixels, regardless of how large the image is displayed.
Positional notation
Positional notation gives each digit a value determined by both the digit itself and its place within the written number.
Moving a 1 from the ones place to the eights place changes its contribution from one to eight.
Precision
A numeric format’s precision describes how much significant detail it keeps; floating-point fraction bits control the spacing at a given scale.
Binary64 keeps more significant bits than binary32, which usually reduces rounding error for the same input.
Prefix-free code
A prefix-free code has no codeword that is the start of another, allowing a decoder to recognize symbols without added separators.
With A = 0, B = 10, and C = 11, the bits 011 decode immediately as A followed by C.

Q

Quantization
Quantization rounds a measured sample amplitude to one of the available stored levels, introducing an error that can appear as noise.
Raising bit depth makes quantization levels closer together without changing when the samples are taken.

R

Range
A numeric format’s range describes the magnitudes it can represent, with floating-point exponent bits setting its broad scale limits.
A value can lie inside binary32’s finite range while still falling between two representable neighbors.
Rasterization
Rasterization turns shape instructions into a pixel grid at a chosen resolution so that a display can show the resulting image.
A vector font outline is rasterized into screen pixels when a document displays its letters.
Redundancy
Redundancy is repeated or predictable information that can allow data to be described more briefly without losing its original content.
A long single-color row has redundancy that run-length encoding can replace with a short count.
Resolution
A representation’s resolution is the smallest distinguishable step at its chosen scale; fixed point sets it through the fraction-bit count.
Five binary fraction bits give a step of 1/32, so a value halfway between those steps needs rounding.
RGB
RGB represents a color through red, green, and blue light intensities, commonly with eight bits for each channel in a pixel.
Full red and green with no blue give the yellow light of RGB (255, 255, 0).
Rounding error
Rounding error is the difference between an intended exact value and the representable value chosen to store or calculate it.
The repeating binary expansion of 0.1 is rounded when stored in either finite single or double precision.
Run-length encoding
Run-length encoding replaces a consecutive run of one symbol with its count and symbol, working best when identical runs are long.
Under a count-and-symbol convention, "MMMMMMNN" becomes "6M2N", while alternating symbols can expand.

S

Sample
An audio sample is one measurement of a signal’s amplitude at a particular time, stored as a number at the recording’s bit depth.
A stereo sampling instant produces a measurement for each of the two channels, increasing the stored data.
Sample rate
The sample rate is the number of measurements per second in each audio channel, measured in hertz, which determines their time spacing.
At 48 kHz, the recorder takes 48,000 measurements each second for each channel in the recording.
Sampling theorem
The sampling theorem requires a rate greater than twice the highest retained signal frequency for faithful sampling of a band-limited signal.
A signal retained through 18 kHz needs a rate above 36 kHz, with filtering to remove higher frequencies.
SI storage prefix
An SI storage prefix scales a storage unit by a decimal power, such as a thousand for kilo or a million for mega.
A 2 MB payload contains 2,000,000 bytes, even when a system also reports its size in MiB.
Sign bit
A sign bit is a bit that indicates whether a signed value is negative, with its interpretation determined by the number format.
In two’s complement a leading 1 indicates a negative value and also carries a negative place weight.
Sign extension
Sign extension widens a signed integer by copying its sign bit into each new position on the left, preserving the value.
The four-bit signed value 1010 widens to 11111010, preserving −6 in eight-bit two’s complement.
Sign-magnitude
Sign-magnitude stores a sign bit separately from the positive magnitude bits, giving distinct positive-zero and negative-zero patterns.
In eight-bit sign-magnitude, 10000110 means −6; the lower seven bits directly give the magnitude.
Significand
A significand is the significant digit sequence scaled by a power of the base; a normal binary significand begins with 1.
In 1.011₂ × 2⁴, the significand is 1.011₂, while the exponent controls its overall scale.
Subnormal value
A subnormal value is a very small floating-point value with an all-zero exponent field, a nonzero fraction, and no hidden leading 1.
Subnormal patterns fill some of the gap between the smallest positive normal value and zero.

T

Ties to even
Ties to even resolves an exact halfway rounding case by choosing the representable value with an even last retained significand bit.
A halfway single-precision integer near 2²⁴ can round downward even though another halfway value rounds upward.
Two's complement
Two's complement is a signed integer representation whose top bit has a negative weight and whose remaining bits keep positive binary weights.
The pattern 11111010 represents −6 in an eight-bit signed field, but 250 if interpreted as unsigned.

U

Underflow
Underflow concerns results that become too small for normal floating-point representation and may be stored as subnormal values or zero.
A calculation approaching zero can lose relative precision as its results enter the subnormal range.
Unicode
Unicode is a shared character standard that assigns code points across writing systems and defines encodings for storing valid character values.
The letters "A", "Ж", and "中" have distinct Unicode code points within the same code space.
Unsigned integer
An unsigned integer represents a nonnegative whole number using positive binary weights in every position of a fixed width.
The byte 11111111 represents 255 when its data type specifies an unsigned eight-bit integer.
UTF-8
UTF-8 is a variable-length Unicode encoding that uses one to four bytes per valid character code point and preserves ASCII bytes.
The word "café" uses five UTF-8 bytes because its final letter needs a two-byte sequence.
UTF-16
UTF-16 encodes valid character values in one or two 16-bit code units, using a surrogate pair for values above U+FFFF.
The emoji "😀" occupies two UTF-16 code units, D83D and DE00, although it is one code point.

V

Vector graphics
Vector graphics describe shapes through geometric instructions, enabling them to be redrawn at different sizes without enlarging a stored pixel grid.
An SVG logo can describe a circle’s center and radius, then redraw that circle for a larger display.

W

Wraparound
Wraparound is behavior that keeps only a fixed number of low bits, making stored integer values cycle through the available patterns.
With eight-bit unsigned wraparound, increasing 254 by three stores 1 after a full cycle of 256.

#

0x prefix
The 0x prefix marks the digits that follow as hexadecimal notation; it is a notation marker and adds no numeric place.
In 0x3A, the digits 3 and A contribute three sixteens and ten ones; the prefix identifies the base.

About this lesson

By StudeliReport a mistake

Make your own Study Materials

Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.

Get Started