Data Representation

Leaving Cert Higher Level Computer Science revision notes with diagrams, key terms and self-check questions.

14 min readHigher LevelBy Studytok
Practise this topic — free →

This topic explains how numbers, text and real-world measurements are all stored as binary, and how to convert between binary, decimal and hexadecimal. At the hardware level, digital computers store and process all information using electrical signals that correspond to the on and off states of transistors. Understanding data representation involves mastering conversions across number bases, tracing binary addition and overflow, comparing character encoding standards like ASCII and Unicode, and working with data types in Python.

Analogue vs Digital Data and Why Computers Use Binary

Physical phenomena in the natural world are continuous. Sound waves, ambient temperature and light levels change smoothly across an infinite range of values. In contrast, digital computer systems work with discrete values.

Continuous vs Discrete Data

  • Continuous data can take any real numerical value within a given range and cannot be counted as separate individual steps (for example, the exact temperature of a room over time).
  • Discrete data consists of distinct, separate, countable values with clear gaps between them (for example, the number of students in a classroom or the count of goals in a match).

Hardware Inputs

  • Analogue inputs: Sensors such as a Light Dependent Resistor (LDR) or a thermistor produce a continuously varying electrical voltage.
  • Digital inputs: Devices like push buttons or toggle switches produce only two distinct electrical states: open (0 V, logic 0) or closed (3.3 V or 5 V, logic 1).

Analogue-to-Digital Conversion (ADC)

Computers cannot store continuous voltages directly. An Analogue-to-Digital Converter (ADC) measures a varying voltage and turns it into a discrete digital number using two steps:

  1. Sampling: The ADC reads the analogue signal at regular, fixed time intervals (for example, 100 times per second).
  2. Quantisation: The measured voltage is rounded to the nearest available digital step. Because values between steps are rounded, a tiny amount of precision is lost.

The number of discrete levels depends on the ADC resolution in bits. An ADC with nn bits provides 2n2^n unique values, from 00 up to 2n12^n - 1. For example, a 10-bit ADC (such as the analogue pins on a BBC micro:bit) yields 210=10242^{10} = 1024 possible integers, ranging from 0 to 1023. If a 10-bit pin runs on a 3.3 V supply and returns a reading of 512, the measured input voltage is approximately half the maximum: 3.3×(512/1023)1.65 V3.3 \times (512 / 1023) \approx 1.65\text{ V}.

A continuous voltage curve is sampled at equal time intervals, then each sampled value is rounded to the nearest available level.
A continuous voltage curve is sampled at equal time intervals, then each sampled value is rounded to the nearest available level.

Why Computers Use Binary

Processors are built from millions of microscopic transistors that function as electronic switches. Each switch operates reliably in one of two physical states: on (conducting current at high voltage) or off (blocking current at low voltage). We label these states with the binary digits 1 and 0.

Using binary provides three key hardware benefits:

  • Reliability and noise tolerance: Distinguishing between two widely separated voltage levels is simple and dependable. Small fluctuations in voltage or electrical noise do not alter a 1 to a 0 unless they cross a wide threshold.
  • Hardware simplicity: Designing circuits and logic gates that check for two states requires far fewer components than building circuits that distinguish between ten distinct voltage levels.
  • Flawless duplication: Binary data can be read, copied and transmitted across long distances without cumulative signal degradation.

Number Bases and Conversions

The base (radix) of a positional number system tells us how many unique symbols it uses. Digit values are determined by place-value columns that increase by powers of the base from right to left.

  • Decimal (Base 10): Uses digits 0–9. Column weights are powers of 10 (100=1,101=10,102=10010^0 = 1, 10^1 = 10, 10^2 = 100, etc.).
  • Binary (Base 2): Uses digits 0 and 1. Column weights are powers of 2 (20=1,21=2,22=4,23=8,24=16,25=32,26=64,27=1282^0 = 1, 2^1 = 2, 2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32, 2^6 = 64, 2^7 = 128).
  • Hexadecimal (Base 16): Uses 16 symbols: 0–9 and A–F (where A=10,B=11,C=12,D=13,E=14,F=15\text{A}=10, \text{B}=11, \text{C}=12, \text{D}=13, \text{E}=14, \text{F}=15). Column weights are powers of 16 (160=1,161=16,162=256,163=409616^0 = 1, 16^1 = 16, 16^2 = 256, 16^3 = 4096).

The Bits and Values Rule

A sequence of nn bits can represent 2n2^n unique values, from 00 up to 2n12^n - 1.

  • 1 nibble (4 bits) gives 24=162^4 = 16 values (0150\text{--}15).
  • 1 byte (8 bits) gives 28=2562^8 = 256 values (02550\text{--}255).

Binary to Decimal

Multiply each bit by its column place value and sum the products. For the byte 10110100:

Value=(1×128)+(0×64)+(1×32)+(1×16)+(0×8)+(1×4)+(0×2)+(0×1)=18010\text{Value} = (1 \times 128) + (0 \times 64) + (1 \times 32) + (1 \times 16) + (0 \times 8) + (1 \times 4) + (0 \times 2) + (0 \times 1) = 180_{10}

Decimal to Binary

Method 1: Place-value subtraction. Compare the decimal value against descending powers of 2 (128 down to 1). If the number is greater than or equal to the column weight, record a 1 and subtract the weight; otherwise, record a 0.

Converting 771077_{10} into an 8-bit byte:

  • 7764177 \ge 64 \rightarrow 1 (leaves 7764=1377 - 64 = 13)
  • 138113 \ge 8 \rightarrow 1 (leaves 138=513 - 8 = 5)
  • 5415 \ge 4 \rightarrow 1 (leaves 54=15 - 4 = 1)
  • 1111 \ge 1 \rightarrow 1 (leaves 11=01 - 1 = 0)

Filling all 8 columns: 7710=01001101277_{10} = 01001101_2.

The byte 01001101 aligns with weights 128 through 1. Its set bits select 64, 8, 4 and 1, which total 77.
The byte 01001101 aligns with weights 128 through 1. Its set bits select 64, 8, 4 and 1, which total 77.

Method 2: Repeated division by 2. Divide the number by 2 repeatedly, recording the integer quotient and the remainder. Read the remainders from bottom to top.

Converting 12110121_{10} to binary:

DivisionQuotientRemainder
121÷2121 \div 2601
60÷260 \div 2300
30÷230 \div 2150
15÷215 \div 271
7÷27 \div 231
3÷23 \div 211
1÷21 \div 201

Reading bottom to top gives 1111001. This is 7 bits long. Pad with a leading zero to form the full 8-bit byte: 01111001. Check: 64+32+16+8+1=12164 + 32 + 16 + 8 + 1 = 121

Quick try: Convert 45 to 8-bit binary. Answer: 32+8+4+1=00101101232 + 8 + 4 + 1 = 00101101_2.

Python Implementation and Trace

We can write this division algorithm in Python:

def to_binary(n):
    bits = ""
    while n > 0:
        bits = str(n % 2) + bits
        n = n // 2
    return bits.zfill(8)

Here % computes the remainder, // performs integer division, and .zfill(8) pads the string with leading zeros.

Tracing to_binary(77):

Iterationn beforen % 2bits after prependn // 2
1771"1"38
2380"01"19
3191"101"9
491"1101"4
540"01101"2
620"001101"1
711"1001101"0

The loop terminates. .zfill(8) prepends one leading zero to return "01001101".

Decimal to Hexadecimal

Method 1: Repeated division by 16. Divide the number by 16 and write down the remainder. Keep dividing the quotient by 16 until the quotient is 0. Read the remainders from bottom to top, writing 10–15 as A–F. (For numbers up to 255 this takes just one division: the quotient is the first digit and the remainder is the second.)

Convert 20110201_{10} to hexadecimal:

  • 201÷16=12201 \div 16 = 12 remainder 99
  • In hex, 12=C12 = \text{C} and 9=99 = 9
  • Result: 20110=C916201_{10} = \text{C}9_{16}

Quick try: Convert 250 to hexadecimal. 250÷16=15250 \div 16 = 15 remainder 1010. Since 15=F15 = \text{F} and 10=A10 = \text{A}, the answer is FA16\text{FA}_{16}. Check: (15×16)+10=250(15 \times 16) + 10 = 250

Method 2: Convert via binary. Convert the decimal number into binary first, split it into 4-bit nibbles, then convert each nibble to hex.

Hexadecimal to Decimal

Multiply each digit by its power of 16. For 3B163\text{B}_{16}:

(3×161)+(11×160)=48+11=5910(3 \times 16^1) + (11 \times 16^0) = 48 + 11 = 59_{10}

Quick try: Convert 1A161\text{A}_{16} to decimal. (1×16)+10=2610(1 \times 16) + 10 = 26_{10}.

Hexadecimal and Binary Relationships

Because 16=2416 = 2^4, each hexadecimal digit corresponds to exactly four binary bits (one nibble). Hexadecimal is human-friendly shorthand that makes long strings of 1s and 0s easier to read, write and debug. The computer hardware always executes code in pure binary.

Hexadecimal Reference Table

HexBinaryDecimalHexBinaryDecimal
000000810008
100011910019
200102A101010
300113B101111
401004C110012
501015D110113
601106E111014
701117F111115
The binary number 110101110 is padded on the left and grouped as 0001, 1010 and 1110, corresponding to hexadecimal 1AE.
The binary number 110101110 is padded on the left and grouped as 0001, 1010 and 1110, corresponding to hexadecimal 1AE.

Converting Between Hex and Binary

  • Binary to Hexadecimal: Group bits into sets of 4 starting from the right (the least significant bit). Pad the leftmost group with leading zeros if it has fewer than 4 bits. Then replace each nibble with its hex symbol.

Example: 110101110 groups into 0001 1010 1110, which converts to 1AE161\text{AE}_{16}.

  • Hexadecimal to Binary: Replace each hex digit with its 4-bit binary equivalent.

Example: C716\text{C}7_{16} becomes 1100 0111 in binary.

Common Uses of Hexadecimal

  • Web colours (RGB): 24-bit colours are written in CSS as #RRGGBB. Each two-digit hex pair represents an 8-bit channel (02550\text{--}255). In #0A33F0, Red is 0A16=100\text{A}_{16} = 10, Green is 3316=5133_{16} = 51, and Blue is F016=240\text{F}0_{16} = 240.
  • Memory addresses: RAM locations (such as 0x7FFE04A2) are displayed in hex to keep diagnostic logs and memory dumps compact.
  • MAC addresses: Network cards carry permanent 48-bit hardware addresses written as six hex pairs (such as 00:1A:2B:3C:4D:5E).

Binary Addition and Overflow Error

Binary addition follows five basic rules, working right to left from the least significant bit:

  • 0+0=00 + 0 = 0
  • 1+0=11 + 0 = 1
  • 0+1=10 + 1 = 1
  • 1+1=01 + 1 = 0, carry 11 into the next column (since 1+1=210=1021 + 1 = 2_{10} = 10_2)
  • 1+1+1=11 + 1 + 1 = 1, carry 11 into the next column (since 1+1+1=310=1121 + 1 + 1 = 3_{10} = 11_2)

Traced Addition: 5810+291058_{10} + 29_{10}

In 8-bit binary: 5810=00111010258_{10} = 00111010_2 and 2910=00011101229_{10} = 00011101_2.

Column Weight1286432168421
Carries111
Operand 1 (58)00111010
Operand 2 (29)00011101
Sum (87)01010111

Summing the active columns: 64+16+4+2+1=871064 + 16 + 4 + 2 + 1 = 87_{10}

Overflow Error

An overflow error occurs when the result of an arithmetic operation exceeds the maximum value that the allocated bit-width can store. For an 8-bit unsigned byte, the largest possible value is 281=2552^8 - 1 = 255.

For example, adding 20010200_{10} and 10010100_{10} in an 8-bit system:

\begin{array}{r@{\quad}l@{}l} & 11001000_2 & (200_{10}) \\ + & 01100100_2 & (100_{10}) \\ \hline 1 & 00101100_2 & (300_{10}) \end{array}

Because the byte can hold only 8 bits, the 9th bit (the carry out of the 272^7 column) is discarded. The stored byte reads 00101100, which equals 44 instead of 300.

The nine-bit result 100101100 represents 300. Only its last eight bits fit in the unsigned byte, leaving 00101100, or 44.
The nine-bit result 100101100 represents 300. Only its last eight bits fit in the unsigned byte, leaving 00101100, or 44.

In Python, integers have arbitrary precision and expand automatically, so 200 + 100 correctly evaluates to 300. Overflow occurs in environments where the bit-width is fixed by hardware, such as microcontroller registers, C variables, or fixed sensor buffers.

Character Encoding Standards: ASCII and Unicode

Computers store characters as numbers. A character encoding standard maps each character to an agreed numeric code.

Why Character Standards Matter

  • Interoperability: Text created on one computer must appear identically on any other device, operating system or software program. This requires universal agreement on which number represents which character.
  • Preventing corrupted text: When sender and receiver use different encodings, characters display as garbled symbols (known as mojibake, such as á replacing á).
  • Global communication: A shared worldwide standard allows software to display multiple languages (Irish, Arabic, Chinese) and modern symbols in the same document.

ASCII (American Standard Code for Information Interchange)

Standard ASCII uses 7 bits to represent 128 characters (codes 0 to 127):

  • Uppercase letters: 'A' = 65 through 'Z' = 90
  • Lowercase letters: 'a' = 97 through 'z' = 122
  • Digit characters: '0' = 48 through '9' = 57 (the character '7' is code 55, not value 7)
  • Control characters: Enter (13), Backspace (8), Escape (27)

ASCII characters are stored inside an 8-bit byte with the most significant bit set to 0. A lowercase letter's code is always 32 higher than its capital ('a' - 'A' = 97 - 65 = 32).

Extended ASCII uses all 8 bits (28=2562^8 = 256 characters). Codes 128–255 include accented vowels (like Irish fadas: á, é, í, ó, ú). However, different countries used conflicting extended code pages, making international file sharing unreliable.

Decoding an ASCII Message

To decode a binary ASCII stream, split the bits into 8-bit bytes, convert each byte to decimal, and look up the character.

Decode 01001000 01101001:

  • First byte: 01001000 =64+8=72’H’= 64 + 8 = 72 \rightarrow \text{'H'}
  • Second byte: 01101001 =64+32+8+1=105’i’= 64 + 32 + 8 + 1 = 105 \rightarrow \text{'i'}
  • Result: "Hi"

Unicode and UTF-8

Unicode is a character set that assigns every character across every human writing system a unique identification number called a code point. Code points are written in hexadecimal prefixed by U+:

  • 'A' = U+0041 (651065_{10}, identical to ASCII)
  • 'á' = U+00E1 (22510225_{10})
  • 👍 = U+1F44D (12807710128077_{10})

UTF-8 is the variable-length encoding format used to store those code points in memory as bytes:

Character TypeUTF-8 Storage Size
Standard English letters (e.g. 'A')1 byte
Accented Latin letters and scripts such as Greek, Cyrillic and Arabic (e.g. 'á')2 bytes
Most Chinese and Japanese characters (e.g. 中)3 bytes
Emojis (e.g. 👍)4 bytes
A, á and thumbs-up map to Unicode code points U+0041, U+00E1 and U+1F44D, then to UTF-8 storage strips of one, two and four bytes.
A, á and thumbs-up map to Unicode code points U+0041, U+00E1 and U+1F44D, then to UTF-8 storage strips of one, two and four bytes.

Exam Comparison: ASCII vs Unicode

  • Memory Usage: ASCII uses a fixed 7 or 8 bits per character, making it compact but limited to 128 (or 256) characters. Unicode (UTF-8) uses a variable width of 1 to 4 bytes per character. English text uses the same memory as ASCII (1 byte), but other languages and emojis consume more memory (2–4 bytes per character).
  • Compatibility: Unicode is backward-compatible with ASCII because its first 128 characters are identical to ASCII. A plain ASCII file is directly readable as UTF-8. Unicode provides global compatibility by supporting all writing systems.

Data Types and Practical Python Operations

High-level programming languages provide abstract data types so programmers do not have to manage raw memory bits directly.

Standard Data Types and Python Equivalents

Syllabus Data TypeDescriptionPython EquivalentExample
BooleanTruth value: True or Falseboolis_active = True
IntegerWhole number without fractionintcount = 42
RealNumber with fractional partsfloatprice = 19.99
CharSingle characterNo separate type: str of length 1grade = 'A'
StringOrdered text sequencestrname = "Leaving Cert"
ArrayOrdered indexed collectionlistscores = [10, 20, 30]
DateCalendar date representationdatetime.datedate(2027, 6, 4)

Type Conversion (Casting) in Python

In Python, the input() function always returns a string. Mixing raw input with a number, such as age_text + 1, causes a TypeError. Adding two raw inputs does not cause an error: it joins them as text ('5' + '3' gives '53'). Convert with int() or float() before doing arithmetic. Variables must be explicitly cast to the appropriate type:

age_text = input("Enter your age: ")
age = int(age_text)  # explicit casting to integer
next_year = age + 1

Storing values in the wrong data type (such as recording a price as '€10' instead of a numeric float 10.00) causes data inconsistencies and stops algorithms from performing calculations.

Built-in Python Conversion Tools

  • ord('A') returns 65 (gets the integer code for a character).
  • chr(97) returns 'a' (gets the character for an integer code).
  • bin(77) returns '0b1001101' (converts decimal integer to binary string).
  • hex(201) returns '0xc9' (converts decimal integer to hexadecimal string).
  • int('C9', 16) returns 201 (converts a hex string to base 10).
  • int('01111001', 2) returns 121 (converts a binary string to base 10).
  • format(121, '08b') returns '01111001' (formats an integer as an 8-bit binary string padded with leading zeros).

Key terms

Bit
The smallest unit of data in computing, holding a single binary state of 0 or 1.
Byte
A group of 8 bits capable of representing 256 distinct values (282^8).
Nibble
A group of 4 binary bits, which corresponds to exactly one hexadecimal digit.
Hexadecimal
A base-16 positional number system using digits 0–9 and letters A–F, used as a human-readable shorthand for binary.
Overflow Error
An error that occurs when an arithmetic calculation produces a result exceeding the maximum value that the allocated bit-width can hold.
ASCII
A 7-bit character encoding system assigning numbers from 0 to 127 to English letters, digits, punctuation and control codes.
Unicode
A universal character set that assigns a unique hexadecimal code point to every character across all human writing systems and emojis.
UTF-8
A variable-length encoding format using 1 to 4 bytes per character to store Unicode code points, fully backward-compatible with ASCII.
Continuous Data
Data that can take any real value within a continuous range, such as temperature, sound or analogue voltage.
Discrete Data
Data that consists of separate, distinct, countable values with clear steps between them.
Analogue-to-Digital Converter (ADC)
A hardware component that samples a continuously varying analogue voltage and converts it into a discrete digital number.

Check yourself

  1. How many bits are needed to give 200 students each a unique binary ID?

    8 bits. 7 bits can only represent 2^7 = 128 values, which is too few. 8 bits represent 2^8 = 256 values, which is sufficient for 200 students.

  2. Convert the hexadecimal number 1F44D into binary, and identify its significance in character encoding.

    0001 1111 0100 0100 1101. (1 = 0001, F = 1111, 4 = 0100, 4 = 0100, D = 1101). In Unicode, U+1F44D is the code point for the thumbs-up emoji (👍).

  3. Why does adding 200 and 100 in an 8-bit unsigned hardware register cause an overflow error?

    An 8-bit unsigned register can only hold values from 0 up to 2^8 - 1 = 255. The sum 300 produces a 9-bit binary result (100101100_2); the 9th bit is lost, leaving the register with the incorrect truncated value 44.

  4. Why is UTF-8 described as being backward-compatible with ASCII?

    The first 128 character codes in UTF-8 (values 0 to 127) are identical to 7-bit ASCII, meaning any existing ASCII file is already a valid UTF-8 file.

  5. What is the reading range of a 10-bit ADC, and what voltage does a reading of 512 represent on a 3.3 V reference pin?

    A 10-bit ADC provides 2^10 = 1024 discrete steps, ranging from 0 to 1023. A reading of 512 represents approximately half the reference voltage: 3.3 V * (512 / 1023) ≈ 1.65 V.

You've read the theory
Now turn it into exam marks.

Practise data representation as questions and flashcards in Studytok, with explanations when you get stuck.

Continue for free →
  1. Read the notes
    6 sections
  2. 2
    Test yourself
    Questions marked instantly
  3. 3
    Keep revising
    Flashcards and exam-style practice