UNIHIVE

Study Hub UNIPORT CSC 283

CSC 283 · Information Systems and File Structures

Data types and how they are stored

Characters, integers, reals, dates and logical values, how many bytes each needs, and fixed against variable fields.

Our notes

2 min read

Why types matter

The type of a field decides what values it can hold, what operations make sense and how much space it takes. Choosing types well saves space and prevents errors (you cannot add two surnames).

Common types

TypeHoldsUsual size
Character (string)letters, digits as text1 byte per character (ASCII); 1-4 bytes per character in UTF-8
Integerwhole numbers2 bytes (−32,768 to 32,767), 4 bytes (about ±2.1 × 10⁹) or 8
Real (floating point)numbers with fractions4 bytes (about 7 significant digits) or 8 (about 15)
Booleantrue or false1 bit in theory, often 1 byte
Dateday, month, year4 to 8 bytes, or 8 characters YYYYMMDD
Packed decimalmoney in exact decimal2 digits per byte

Characters

  • ASCII uses 7 bits (128 characters); "A" = 65, "a" = 97, "0" = 48.
  • EBCDIC (IBM mainframes) uses 8 bits with different codes.
  • Unicode covers every script, including Yoruba, Igbo and Hausa letters with diacritics (ẹ, ọ, ṣ, ƙ). UTF-8 stores plain English letters in 1 byte and others in 2 to 4.

Numbers stored as text or as numbers

A phone number like 08031234567 should be stored as text: it is never added, and storing it as an integer drops the leading zero. A score should be an integer so it can be totalled and averaged.

Integer range

An n-bit two's complement integer holds −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1.

  • 16 bits: −32,768 to 32,767.
  • 32 bits: −2,147,483,648 to 2,147,483,647.

Example: a bank storing balances in kobo in a 32-bit integer could only hold up to ₦21,474,836.47: too small. Use 64 bits or packed decimal.

Fixed and variable length fields

  • Fixed length: every record gives the field the same space (surname 20 characters). Easy to locate fields; wastes space when values are short, and truncates long ones.
  • Variable length: each value takes only the space it needs, marked by a length prefix or a delimiter (comma, tab). Saves space; harder to update in place.

Example: if surnames average 8 characters, a fixed 20-character field wastes 12 bytes per record: for 25,000 records, 300,000 bytes.

Coding to save space

Store codes instead of long text: "CSC" instead of "Computer Science", 1 or 2 for semester. Keep the meanings in a small reference (code) file.

Exams usually ask

  • List data types with typical sizes.
  • Explain why some numbers are stored as text.
  • Compare fixed and variable length fields.

Common mistake

Storing money as a 4-byte real. Floating point cannot hold 0.10 exactly, so totals drift by fractions of a kobo; use integers in kobo or a decimal type.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

No reading links here yet

Our team adds free books, videos and practice for each topic, and opens every link before it goes up.

All CSC 283 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.