Clastify logo
Subjects
Features
Review
HOT
Tutoring

A1.2: Data representation and computer logic

Master IB Computer Science A1.2: Data representation and computer logic with notes created by examiners and strictly aligned with the syllabus.

This content can't be printed from the browser. Use Export PDF with Pro for an offline copy.

IB Syllabus Requirements for Data representation and computer logic

A1.2.1

Representing integers and converting number bases

A1.2.2

Storing data using binary encoding

A1.2.3

Logic gates and Boolean operators

A1.2.4

Building truth tables and simplifying expressions

A1.2.1

REPRESENTING INTEGERS AND CONVERTING NUMBER BASES

Writing an integer in a different number base changes how it looks, but its value stays the same. You should be able to explain the place-value system and convert integers between binary, decimal and hexadecimal.

Binary, decimal and hexadecimal

Binary uses base 2, so its only digits are 0 and 1. Each digit is a bit. Moving one position to the left doubles the place value.

In Decimal, also called denary, the base is 10 and the digits are 0–9. Each place value is a power of 10.

Hexadecimal uses base 16, with digits 0–9 and letters A–F. Those letters stand for decimal values 10–15.

Hexadecimal digitABCDEF
Decimal value101112131415

The examples here use non-negative integers. Leading zeros don't change the value: binary 00101101 and binary 101101 represent the same integer.

Binary to decimal

Start by writing the place value above each bit of binary 00101101. Multiply each bit by its place value, then add the results. The figure shows why this bit pattern represents decimal 45.

Binary place values and contributions for 00101101.

Place value1286432168421
Bit00101101
Contribution003208401
Total3232884411
Decimal value4545
Place value1286432168421
Bit00101101
Contribution003208401

Decimal value = 0 + 0 + 32 + 0 + 8 + 4 + 0 + 1 = 45.

Decimal to binary

Divide the decimal integer by 2 and record the remainder. Keep dividing each quotient by 2 until the quotient is 0.

DivisionQuotientRemainder
45 divided by 2221
22 divided by 2110
11 divided by 251
5 divided by 221
2 divided by 210
1 divided by 201

Read the remainders from bottom to top to get 101101. If you need an eight-bit representation, add leading zeros: 00101101.

Hexadecimal to decimal

From right to left, hexadecimal place values begin 1, 16 and 256. For hexadecimal 2D:

  • The digit 2 contributes 2 × 16 = 32.
  • D stands for 13, so it contributes 13 × 1 = 13.
  • Add these contributions: 32 + 13 = 45.

Decimal to hexadecimal

Divide repeatedly by 16, recording the remainder at each step.

DivisionQuotientRemainder
45 divided by 16213, written D
2 divided by 1602

Reading the remainders from bottom to top gives 2D.

Binary to hexadecimal

Four bits have 16 possible patterns, so one hexadecimal digit corresponds to exactly four bits. This makes hexadecimal a shorter, more readable way to write binary values.

To convert binary 00101101:

  1. Starting at the right, group the bits into sets of four: 0010 and 1101.
  2. Convert 0010: 0 + 0 + 2 + 0 = 2.
  3. Convert 1101: 8 + 4 + 0 + 1 = 13, written D.
  4. Keep the groups in their original order to get hexadecimal 2D.

If the leftmost group has fewer than four bits, complete it with leading zeros.

Hexadecimal to binary

Work on each hexadecimal digit separately. Convert it into four bits, then join the groups.

  1. For 2, use the four-bit place values 8, 4, 2, 1: only the 2 position is needed, giving 0010.
  2. For D, use its decimal value 13: 13 = 8 + 4 + 1, giving 1101.
  3. Join the groups: 00101101.

Terms to use: binary, hexadecimal, decimal, integer, bit.

A1.2.2

STORING DATA USING BINARY ENCODING

Binary storage assigns bit patterns to values. To explain how it works, start with the original data and its encoding. Show how that encoding becomes bits, then explain how the system interprets those bits when it retrieves them.

Encoding and interpretation

Binary encoding represents data as patterns of 0s and 1s. Computer hardware distinguishes between two physical states, such as two voltage ranges, and treats them as binary values.

A byte contains eight bits. Storage systems hold sequences of bits, but the encoding and format determine what those sequences mean.

Take the byte 01000001. It can represent the integer 65. Under a character encoding that assigns 65 to the character A, that same byte represents A instead. The bits alone don't tell the system which interpretation to use.

The encoding process figure follows original data → encoding → stored bits → decoding → retrieved data. To retrieve the data correctly, the system needs both the stored bits and the rules for decoding them.

Integers

An integer uses a binary bit pattern with positional values. For example, decimal 45 can be stored as 00101101 in an eight-bit field.

The number of bits allocated limits how many different values can be represented. Eight bits provide 256 patterns. If all of them represent non-negative integers, the range is 0–255. More bits allow a larger range, but each value then takes up more storage.

Characters and strings

A character encoding assigns numeric codes to characters. These codes are then represented in binary.

ASCII and Unicode are examples of systems for representing characters. Unicode supports a much wider range of writing systems and symbols. An encoding such as UTF-8 determines how Unicode characters are stored as bytes.

A string is a sequence of characters, stored as their encoded representations in the same order. In a variable-length encoding, different characters can need different numbers of bytes. Character count alone therefore doesn't determine storage size.

Images

A bitmap image stores a grid of pixels, each with a binary value describing its colour or brightness.

The image format must identify the image dimensions and specify how to interpret the pixel values. An RGB representation, for example, stores red, green and blue components for each pixel.

Two choices directly affect storage:

  • Resolution: more pixels mean more pixel values to store.
  • Colour depth: more bits per pixel allow more possible colours but require more storage per pixel.

For an uncompressed image, storage for the pixel data is width × height × bits per pixel. Format information adds to this total.

Audio

Digital audio stores measurements of a sound signal taken at regular intervals. Each sample uses a binary value to approximate the signal's amplitude at that instant.

The sample rate is the number of samples taken per second. Bit depth is the number of bits used to represent each sample.

A higher sample rate records changes in the signal more frequently; a greater bit depth provides more possible amplitude values. Both increase the amount of uncompressed audio data. Duration and the number of audio channels also affect storage.

Video

Digital video represents moving images through a sequence of frames. Each frame contains encoded image information, while timing information determines when it is displayed. Video may also include an audio stream that must stay synchronized with the frames.

Higher frame resolution and greater colour depth generally increase the amount of uncompressed video data, as do a higher frame rate and a longer duration. Compression can reduce the stored size by representing the content more efficiently.

The comparison figure links each data type to the information its bits represent.

How binary values are interpreted for common data types.

Data typeWhat the binary data representsInformation needed for interpretation
IntegerA numeric valueNumber representation and field width
CharacterA character codeCharacter encoding
StringAn ordered sequence of character codesCharacter encoding and sequence boundaries
ImagePixel colours or brightness valuesDimensions, colour depth and image format
AudioA sequence of amplitude samplesSample rate, bit depth and channels
VideoFrames, timing information and possibly audioFrame dimensions, frame rate and video format
Data typeWhat the binary data representsInformation needed for interpretation
IntegerA numeric valueNumber representation and field width
CharacterA character codeCharacter encoding
StringAn ordered sequence of character codesCharacter encoding and sequence boundaries
ImagePixel colours or brightness valuesDimensions, colour depth and image format
AudioA sequence of amplitude samplesSample rate, bit depth and channels
VideoFrames, timing information and possibly audioFrame dimensions, frame rate and video format

Effects on storage and retrieval

Storage requirements depend on how many values are represented and how many bits each value needs. More detail usually means more data to store and transfer.

To retrieve data, the system must locate it and decode it using the correct format. Some formats place values in fixed positions. Others require the system to interpret variable-length data or decompress it. Using an incorrect encoding can produce unreadable text or incorrectly interpreted media, even when the stored bits haven't changed.

Terms to use: binary encoding, data storage, retrieval, integers, strings, characters, images, audio, video.

A1.2.3

LOGIC GATES AND BOOLEAN OPERATORS

Logic gates take binary inputs, perform operations on them and produce binary outputs. You should be able to describe what each gate does and explain how gates support computation and control in a computer.

Gates and binary computing

A logic gate is an electronic circuit that carries out a Boolean operation. Two logical states represent its inputs and output: 0 and 1, which can also be interpreted as false and true.

A Boolean operator gives the rule for combining or changing Boolean values. The gate carries out that rule in hardware, while the operator can also be used in a Boolean expression.

Most gates covered here take two inputs, A and B. NOT takes just one. When gates are connected, the output of one operation becomes the input of another. Simple operations can therefore build more complex circuits.

The seven operators

OperatorOutput ruleOutput is 1 when…
ANDBoth inputs must be 1A = 1 and B = 1
ORAt least one input must be 1A = 1, B = 1, or both
NOTInverts its single inputIts input is 0
NANDThe inverse of ANDThe inputs are not both 1
NORThe inverse of ORBoth inputs are 0
XORThe inputs must differExactly one input is 1
XNORThe inputs must matchBoth are 0 or both are 1

OR is inclusive: when both inputs are 1, it still produces 1. XOR excludes that case. NAND, NOR and XNOR invert AND, OR and XOR respectively.

Compare how the two-input gates respond to the same inputs in the table below.

Truth-table comparison with each gate beside its inverted counterpart.

ABANDNANDORNORXORXNOR
00010101
01011010
10011010
11101001
ABA AND BA OR BA NAND BA NOR BA XOR BA XNOR B
00001101
01011010
10011010
11110001

For NOT, there are only two possible input cases:

ANOT A
01
10

Functions in computer systems

Gates turn binary representations into useful actions and results. For example:

  • Control: AND can require both an enable signal and a condition to be true before an operation proceeds. OR can activate an alert if either of two fault signals is true.
  • Arithmetic: When adding two single bits, XOR gives the sum bit. AND gives the carry bit for those inputs.
  • Comparison: XNOR produces 1 when two bits match; XOR produces 1 when they differ.
  • Inversion: NOT reverses a control signal. NAND and NOR each combine a test with inversion in one gate.

These aren't the only possible uses. Networks of gates in a computer implement arithmetic, comparisons and decisions by applying the same Boolean rules repeatedly to binary signals.

Terms to use: logic gates, binary computing, Boolean operators, AND, OR, NOT, NAND, NOR, XOR, XNOR.

A1.2.4

BUILDING TRUTH TABLES AND SIMPLIFYING EXPRESSIONS

To construct a truth table, list every possible input combination, then work through the logic one operation at a time. To analyse it, find the rows where the output is 1. Check whether a simpler expression gives exactly the same outputs.

From a problem description to an expression

A room-access system releases a door only when a pass is valid and either the holder is a supervisor or restricted hours are not in effect.

First, define exactly what each input and the output represent:

  • A = 1 means the pass is valid.
  • B = 1 means the holder is a supervisor.
  • C = 1 means restricted hours are in effect.
  • Y = 1 means release the door.

This gives the Boolean expression Y = A AND (B OR NOT C). The brackets tell you to calculate the OR result before combining it with A.

Build the truth table column by column

With n independent binary inputs, there are 2 to the power n possible input combinations. For three inputs, you need eight rows.

List A, B and C in a systematic binary-counting order. Calculate NOT C first. Use that result to find B OR NOT C, then apply the final AND with A. The figure includes these intermediate columns alongside the output.

Worked truth table for the room-access expression.

AABBCCNOT CCBB OR NOT CCY=AY = A AND (B(B OR NOT C)C)
000110
001000
010110
011010
100111
101000
110111
111011
ABCNOT CB OR NOT CY = A AND (B OR NOT C)
000110
001000
010110
011010
100111
101000
110111
111011

Take the row where A = 1, B = 0 and C = 1. NOT C is 0, which makes the OR result 0 too. The pass is valid, but the door remains locked.

Deriving a table from a logic diagram

Work through the diagram from its inputs towards its output. Name each intermediate gate output and give it a column in the table. Don't skip a gate just because the full expression looks familiar.

For the room-access circuit, work through the gates in this order:

  1. A NOT gate receives C and produces N = NOT C.
  2. An OR gate receives B and N and produces T = B OR N.
  3. An AND gate receives A and T and produces Y = A AND T.

N and T correspond to the NOT C and B OR NOT C columns in the table above. Working gate by gate predicts the circuit's output for every possible input.

Recovering an expression from output rows

You can also work backwards from a truth table to an expression. For each row where Y = 1, write an AND term that matches that exact input combination. Keep an input unchanged if its value is 1; negate it if its value is 0. Then join the terms with OR.

Here, the output is 1 for input combinations 100, 110 and 111. These give:

Y = (A AND NOT B AND NOT C) OR (A AND B AND NOT C) OR (A AND B AND C).

The expression is correct, but it can be shorter. Any simplified expression must preserve the output in every row—not just in selected cases.

Karnaugh maps

A Karnaugh map arranges truth-table outputs so that neighbouring cells differ in only one input. Grouping adjacent 1s shows which inputs can be removed from terms.

For this three-input example, put A on the rows and BC on the columns. Use the column order 00, 01, 11, 10, rather than ordinary binary-counting order. The map wraps around, so the first and last columns are adjacent too.

Three-input Karnaugh map; overlap at BC=10BC=10 and wrap-around pair 0000–1010.

AA / BCBC00011110
00000
11011
A / BC00011110
00000
11011

Arrange adjacent 1s into rectangular groups containing a power-of-two number of cells, such as 1, 2, 4 or 8. Choose the largest valid groups. Every 1 must be covered, and no group may include a 0. Groups can overlap.

For this map:

  • Group the cells in row A = 1 at BC = 00 and BC = 10. They touch across the wrap-around boundary. B changes, while A = 1 and C = 0 stay constant, giving A AND NOT C.
  • Group the cells in row A = 1 at BC = 10 and BC = 11. Here C changes, while A = 1 and B = 1 stay constant, giving A AND B.

Join the groups to get Y = (A AND NOT C) OR (A AND B). The cell at BC = 10 belongs to both groups; that overlap is allowed.

Algebraic simplification

Boolean algebra offers another way to reach the same result. Start with the three output-1 terms:

  1. Combine the terms for 110 and 111 by factoring out A AND B: (A AND B) AND (NOT C OR C).
  2. NOT C OR C is always 1, so the two terms reduce to A AND B.
  3. The expression is now (A AND NOT B AND NOT C) OR (A AND B).
  4. Factor out A: A AND ((NOT B AND NOT C) OR B).
  5. Distribute OR over AND to get (B OR NOT B) AND (B OR NOT C) inside the brackets.
  6. B OR NOT B is 1, leaving A AND (B OR NOT C).

Using the distributive rule, the Karnaugh-map result factors to the same expression. Equivalent expressions may look different on the page. Identical truth-table outputs establish that they implement the same logic.

Terms to use: truth table, inputs, outputs, Boolean expression, logic diagram, Karnaugh map, algebraic simplification.

A1.2.5

CONSTRUCTING AND SIMPLIFYING LOGIC DIAGRAMS

To construct a logic diagram, turn each Boolean operation into a gate, then connect the gates in the order the expression requires. Label the inputs and intermediate signals, along with the final output, so the flow of information is clear.

Standard gate symbols

A logic diagram shows gates and the connections that carry signals between them. In the commonly used shaped-symbol notation, a small circle called an inversion bubble shows that a signal is inverted.

GateStandard symbol features
ANDFlat input side and rounded output side, forming a D-like shape
ORCurved input side and curved sides meeting at a pointed output
NOTTriangle with an inversion bubble at its output
NANDAND symbol with an inversion bubble at its output
NOROR symbol with an inversion bubble at its output
XOROR symbol with an additional curved line on the input side
XNORXOR symbol with an inversion bubble at its output

NOT has one input; the other gates in these examples have two. Keep signal flow consistent, normally from left to right. Inputs enter the input side of each gate, and the output leaves the output side.

Mark connected wires with a junction dot. If wires cross without a junction dot, don't treat them as connected.

Worked construction from an expression

For Y = A AND (B OR NOT C), build the circuit from the innermost operation outwards:

  1. Place inputs A, B and C on the left and output Y on the right.
  2. Draw a NOT gate on the C wire and label its output N.
  3. Feed B and N into an OR gate. Label its output T.
  4. Feed A and T into an AND gate. Label its output Y.

The signal relationships are N = NOT C, T = B OR N and Y = A AND T. A goes directly to the final AND gate, not through the OR gate.

For A = 1, B = 0 and C = 0, the NOT gate produces N = 1. The OR gate then produces T = 1, and the AND gate produces Y = 1. Working through the connections this way follows the order in which the signal is processed.

Combining gates for more complex operations

The output of one gate can feed another, while a signal can branch to several gate inputs. The connections determine the expression. Correct gate types connected in the wrong order do not produce an equivalent circuit.

For example, implement Y = NOT ((A AND B) OR C) as follows:

  1. Feed A and B into an AND gate, producing P.
  2. Feed P and C into an OR gate, producing Q.
  3. Feed Q into a NOT gate, producing Y.

You can replace the final OR and NOT with a single NOR gate receiving P and C. An AND followed by NOT can likewise be replaced by NAND; an XOR followed by NOT can be replaced by XNOR.

Boolean algebra rules

Simplify the expression using Boolean algebra before redrawing the circuit. In the table, 0 means false and 1 means true. A, B and C are Boolean values or expressions.

RuleEquivalent forms
IdentityA AND 1 = A; A OR 0 = A
DominationA AND 0 = 0; A OR 1 = 1
IdempotenceA AND A = A; A OR A = A
ComplementA AND NOT A = 0; A OR NOT A = 1
Double negationNOT NOT A = A
CommutativeA AND B = B AND A; A OR B = B OR A
Associative(A AND B) AND C = A AND (B AND C); (A OR B) OR C = A OR (B OR C)
DistributiveA AND (B OR C) = (A AND B) OR (A AND C); A OR (B AND C) = (A OR B) AND (A OR C)
AbsorptionA OR (A AND B) = A; A AND (A OR B) = A
De Morgan's lawsNOT (A AND B) = (NOT A) OR (NOT B); NOT (A OR B) = (NOT A) AND (NOT B)

When applying De Morgan's laws, make both changes: switch AND with OR and invert each operand. Moving a NOT symbol inside the brackets isn't enough.

Worked circuit simplification

Take Z = (A AND B) OR (A AND NOT B). First construct the original circuit:

  1. Branch B: send one branch to an AND gate and the other through a NOT gate, producing N = NOT B.
  2. Branch A to two AND gates.
  3. Feed A and B into the first AND gate, producing P = A AND B.
  4. Feed A and N into the second AND gate, producing Q = A AND NOT B.
  5. Feed P and Q into an OR gate, producing Z.

Now simplify the expression step by step:

  • Use the distributive rule to factor out A: Z = A AND (B OR NOT B).
  • Apply the complement rule: Z = A AND 1.
  • Apply the identity rule: Z = A.

The simplified diagram needs only a connection from A to Z. B no longer affects the output. No gates are needed for this function.

The equivalence table checks every input combination. It confirms that the original circuit and the direct connection produce identical outputs.

Equivalence of the original and simplified expressions for all input combinations.

ABP = A AND BQ = A AND NOT BOriginal Z = P OR QSimplified Z = A
000000
010000
100111
111011
ABP = A AND BQ = A AND NOT BOriginal Z = P OR QSimplified Z = A
000000
010000
100111
111011

A simpler diagram can use fewer gates and connections. It is valid only if the output stays unchanged for every possible input combination.

Terms to use: logic diagram, standard gate symbols, inputs, outputs, AND, OR, NOT, NAND, NOR, XOR, XNOR, Boolean algebra.

Were those notes helpful?

A1.1 Computer hardware and operation

A1.3 Operating systems and control systems