Topic 4 · Notes

Data types, representation and compression

These notes are part of a subscription

15 sections covering the whole specification for this topic, with worked examples.

Preview

Data types

A data type tells the computer what kind of data a variable holds. This decides how much memory it needs, how it is stored in binary, and what you can do with it (you can multiply numbers, but not names).

Data typeHoldsExample
BooleanOnly TRUE or FALSE, used for conditionsvalid = True
CharacterA single letter, digit or symbolletter = 'A'
IntegerWhole numbers, positive or negativeage = 15
RealNumbers with a decimal point (also called float)temperature = 36.4
StringA sequence of characters: letters, digits, symbols, spacesemail = 'computer.science@wjec.co.uk'

Choosing the right type

DataBest typeWhy
Number of students in a classIntegerAlways whole
Price of an item, £3.99RealHas a decimal part
Whether a member has paidBooleanOnly yes or no
A grade, e.g. 'B'CharacterOne character
A phone number, 07700 900123StringNot used in calculations, it may start with 0 (an integer would lose it), and it can contain spaces or a +
A postcode, SA10 6YYStringMix of letters, digits and a space

In WJEC pseudo-code a variable's type is given like this: myvariable is integer.

Also in these notes

  • Number systems
  • Converting binary and denary
  • Converting with hexadecimal
  • Binary addition
  • Arithmetic shifts
  • Overflow and underflow
  • Characters: ASCII and Unicode
  • Storing graphics
  • Calculating image file sizes
  • Storing sound
  • Calculating sound file sizes
  • Data storage units
  • Compression
  • Compression calculations