Data Format Selection

The same information can be stored in several ways. A temperature might be stored as readable characters or as a numeric value interpreted using a stated scale. Data Format Selection means choosing a representation that preserves what an application needs while meeting its storage, speed, and compatibility requirements. Start with the information that must survive, then compare the available formats.

Meaning comes before size

A data format is a set of rules describing how stored data is organized and interpreted. It can specify field order, field sizes, character encoding, units, and other information needed to read a record. An internal representation is the encoding a system uses to hold a value during processing. A file format and a program's internal representation can differ: a program may read character data from a file and convert it into numeric values for calculation.


Stored bits do not explain their own meaning. A reader needs the appropriate rules. For example, the characters 0042 may identify a locker. Converting them to the number 42 loses the original width unless a separate rule preserves it. If exactly four digits are required, that rule can reconstruct the identifier. If widths vary and matter, preserve the original characters or sufficient information to reconstruct them. Text storage is a straightforward choice. For digit-only identifiers, another reversible choice is to store the numeric value and original length: the value 731 with length 5 reconstructs 00731, while the same value with length 4 reconstructs 0731.


Metadata can supply units, a scale, field lengths, or a format version. A compact encoding is useful only when the reader has enough information to decode it correctly.

Eliminate formats that lose required information

Write down the required range, resolution, and exactness before choosing a format. Range describes the values that can be represented. Resolution describes the smallest distinguishable increment. A format can cover the full range yet still be too coarse.


Requirement

Suitable direction

What to check

Preserve identifiers as entered

Character data

Leading zeros, permitted characters, and length

Preserve measurements in exact hundredths

Scaled whole-number values

Scale, supported range, and units

Support approximate scientific calculations

Approximate numeric values

Whether representation error meets the application tolerance

Recover every original value after compression

Lossless encoding

Decoder availability and processing cost

Reduce media size when some detail may be discarded

Lossy encoding

Whether the discarded detail is acceptable


A fixed-point representation can store exact hundredths by interpreting each stored unit as 0.01 of the measurement unit. This is useful when the application's permitted values already lie on that grid. It does not make arbitrary values exact.



Reject a format that violates a required constraint before comparing its savings. Lossless compression preserves the original data when decoded correctly; lossy compression permits some information to be discarded. Neither description alone tells you the resulting file size for a particular dataset.

Compare the complete cost

For a format with a fixed header and fixed-size records, use:


S=H+NrS = H + Nr


Here, SS is total storage in bytes, HH is the header size in bytes, NN is the number of records, and rr is the number of bytes per record. Include required metadata rather than comparing record sizes alone.


Example: A file contains 200 records. A text format uses 6 bytes per record with no header, so it needs 1200 bytes. A packed format uses 4 bytes per record and a 32-byte header, so it needs 32+200(4)=83232 + 200(4) = 832 bytes. The saving is 368 bytes, provided both formats satisfy the information requirements.


Three connected boxes show requirements, validity checks, and cost comparison.


Also check reading and writing time, software support, and working memory. When moving multi-byte fields between systems, specify byte order. Readable text may simplify inspection, while a packed format may reduce transfer size but require more decoding.



What to remember

  • Preserve the required meaning, range, resolution, and exactness.
  • Include headers and decoding rules in the comparison.
  • Choose among valid formats using the application's actual costs and constraints.

Example: Choosing a temperature logger format

A greenhouse logger saves 3600 temperature readings in one file. Each reading is an exact multiple of 0.01 °C between −25.00 °C and 75.00 °C, inclusive. Its storage budget, the maximum space available for this file, is 8000 bytes.


Two formats are supported. Text uses exactly 9 bytes per reading, including its separator, and has no header. Scaled format uses 2 bytes per reading plus one 64-byte header. It represents exact multiples of 0.01 °C from −327.68 °C to 327.67 °C. Its header documents the scale, temperature unit, record count, and byte order. Both formats preserve every required value, and neither has additional overhead.


a) Explain whether the scaled format meets the logger's range and resolution requirements.


The required minimum is ________, which is above the supported minimum of −327.68 °C. The required maximum is ________, which is below the supported maximum of 327.67 °C. Therefore, the full required interval is supported.


The required increment is 0.01 °C, exactly the increment that the scaled format preserves. Every permitted reading therefore has an exact representation. The scaled format meets both requirements, and its header supplies the rules needed to interpret the stored values.


b) Calculate the complete file size for each format.


For text, multiply the number of readings by the size of each reading. There is no header:


Stext=3600(9)=32400 bytesS_{\text{text}} = 3600(9) = 32400\ \text{bytes}


For the scaled format, first calculate the space occupied by readings. This is ________. Add its single header of ________:


Sscaled=64+3600(2)=7264 bytesS_{\text{scaled}} = 64 + 3600(2) = 7264\ \text{bytes}


The complete file sizes are 32400 bytes for text and 7264 bytes for scaled format. The header is counted once because it describes the whole file.


c) Select the format that meets the storage budget and calculate its unused space.


Apply the storage limit to the complete file size. The text file needs 32400 bytes, which exceeds the 8000-byte budget. The scaled file needs 7264 bytes, which is within the budget.


Subtract its complete size from the available space:


Unused space=8000−7264=736 bytes\text{Unused space} = 8000 - 7264 = 736\ \text{bytes}


Choose the scaled format, leaving 736 bytes unused. It satisfies the range, resolution, exactness, decoding, and storage requirements given in the problem.

A delivery system receives identifiers such as 004862 and 04862. Their different lengths are significant, and future identifiers may contain letters. Which storage choice best preserves the identifiers without additional reconstruction rules?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A school application exchanges student records with another system. Match each data-format term to the responsibility it describes when records are stored or transmitted.

Match each term
A.

Provides a designated marker that helps a reader recognize a file's type.

B.

Converts structured values into a specified sequence suitable for storage or transmission.

C.

Specifies how character codes become stored or transmitted byte sequences.

D.

Describes field names, allowed types, and structural constraints.

Character encoding

Format signature

Serialization

Schema

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A monitoring device stores exactly 600 readings in one file. Three formats all meet its range and exactness requirements. Each file contains one header followed by the readings, with no other storage overhead. Complete the total sizes as exact integer numbers of bytes and enter yes or no for whether each format fits a 1500-byte limit.

FormatHeader (bytes)Bytes per readingTotal size (bytes)Fits limit
A4002
B1002
C03

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice