IB COMPUTER SCIENCE | A1.2.1 Principal Methods of Representing Data

Lesson objective

Describe integer representation in binary and hexadecimal, convert to and from decimal, and convert directly between binary and hexadecimal using four-bit groups.

Learn

A1.2.1 | PRINCIPAL METHODS OF REPRESENTING DATA

01 | ONE VALUE, DIFFERENT WAYS TO WRITE IT

Imagine a score of twenty-six. We normally write it as 26 using decimal notation. The same value can be written as 11010 in binary or 1A in hexadecimal. The quantity has not changed; the notation used to represent it has.

A number base tells us which digits are available and what each position is worth. Decimal uses base 10, binary base 2 and hexadecimal base 16. Understanding place value lets you explain the conversions instead of memorising an isolated table.

This objective focuses on representing integers in binary and hexadecimal and converting between these and decimal. We begin with non-negative integers. The meaning of a signed bit pattern depends on the agreed representation, which must be specified separately.

The next lesson considers how binary encodings represent stored data more broadly. Here the goal is to understand the number itself: which digits are allowed, what their positions mean and how to recover the value.

02 | DECIMAL: PLACE VALUE YOU ALREADY USE

In decimal, the positions from right to left are worth 1, 10, 100, 1000 and so on. Each position is ten times the one immediately to its right. The digit tells you how many of that position’s value are included.

For example, 326 means three hundreds, two tens and six ones. Its value is 3 × 100 + 2 × 10 + 6 × 1. The same place-value principle works in other bases, but the multiplier between positions changes.

Decimal positionHundredsTensOnes
Power of the base10²10¹10⁰
Position value100101
Digit in 326326
Contribution300206

Any non-zero base raised to power zero gives 1, so the rightmost integer position is the ones position in each of these systems. Moving left multiplies the place value by the base.

03 | BINARY: TWO DIGITS, POWERS OF TWO

Binary uses only the digits 0 and 1. Its positions are worth powers of two: from the right, 1, 2, 4, 8, 16, 32, 64, 128 and so on. A 1 includes that place value; a 0 contributes nothing from that position.

A binary digit is a bit. Eight bits make a byte. Four bits are often called a nibble, a grouping that becomes particularly useful when converting to hexadecimal.

The binary pattern 00011010 has 1s in the 16, 8 and 2 positions, so it represents 16 + 8 + 2 = 26 as an unsigned value.

Place value1286432168421
Bit in the example00011010
Contribution000168020

Leading zeros can show a required width, such as an eight-bit field, without changing a non-negative integer’s value. 11010 and 00011010 therefore have the same unsigned value. A zero appended on the right changes the place values and normally changes the number.

04 | TRY THE EIGHT-BIT PLACE-VALUES

Click a bit to switch it between 0 and 1. Each button shows the bit and its place value. The totals update so you can connect the pattern to its decimal and hexadecimal representations.

Try making 26, then 128, then the largest unsigned value possible with eight bits. Predict which contributions are needed before clicking.

This activity interprets the pattern as unsigned. A different agreed representation can give the same bit pattern a different meaning.

05 | CONVERT BINARY TO DECIMAL

Write the binary digits under their powers-of-two place values. Multiply each digit by its place value and add the contributions. With only 0 and 1 available, you can simply add the headings with a 1 beneath them.

For 101101, start at the right with 1 and work left: 2, 4, 8, 16, 32. The selected headings are 32, 8, 4 and 1. Their sum is 45.

WORKED CONVERSION

101101₂ = 1×32 + 0×16 + 1×8 + 1×4 + 0×2 + 1×1
         = 32 + 8 + 4 + 1
         = 45₁₀

The small subscript indicates the base. 10₂ is two in decimal, while 10₁₀ is ten. Writing the base avoids ambiguity when several number systems appear in the same answer.

06 | CONVERT DECIMAL TO BINARY

One method is to choose powers of two from largest to smallest. For 45, choose 32, leaving 13. Skip 16, then choose 8, 4 and 1. Write a bit for every position, including the zero positions: 101101.

Another method is repeated division by two. Record each remainder, then divide the whole-number quotient again until it becomes zero. Read the remainders from the final row back to the first.

DivisionWhole-number quotientRemainder
45 ÷ 2221
22 ÷ 2110
11 ÷ 251
5 ÷ 221
2 ÷ 210
1 ÷ 201

Reading those remainders bottom to top gives 101101. If eight bits are requested, pad on the left: 00101101. Do not reverse the whole-number quotients or read the remainders in their production order.

07 | HEXADECIMAL: SIXTEEN DIGIT VALUES

Hexadecimal uses sixteen digit values. The familiar symbols 0–9 represent zero to nine; A, B, C, D, E and F represent ten to fifteen. A is one hexadecimal digit, not two digits that should be separately processed as 1 and 0.

The positions from right to left are worth 1, 16, 256, 4096 and so on. Each step left multiplies the position value by sixteen.

Hex digit0123456789ABCDEF
Decimal value0123456789101112131415
Hex position16³16²16¹16⁰
Place value4096256161
Digit in 2AF02AF
Contribution051216015

2AF₁₆ therefore means 2 × 256 + 10 × 16 + 15 = 687₁₀. The displayed leading zero shows the unused 4096 position; it does not change the value.

08 | CONVERT BETWEEN HEXADECIMAL AND DECIMAL

To convert hexadecimal to decimal, multiply each digit’s value by its place value and add the results. For 3C, C means twelve, so the value is 3 × 16 + 12 × 1 = 60.

To convert decimal to hexadecimal, repeated division works again, but divide by sixteen. Map remainders ten to fifteen to A–F, then read the remainders in reverse order.

DivisionWhole-number quotientRemainderHex symbol
687 ÷ 164215F
42 ÷ 16210A
2 ÷ 16022

Reading the symbols bottom to top gives 2AF. A remainder of 10 must become the single symbol A; writing 21015 would not be a correct hexadecimal representation of this result.

Check by reversing the process: 2 × 256 + 10 × 16 + 15 = 687. A conversion method is stronger when you can verify its result in the other direction.

09 | FOUR BITS MATCH ONE HEX DIGIT

Four bits have 2⁴ = 16 possible patterns, from 0000 through 1111. Hexadecimal has exactly sixteen digit values, so each four-bit group maps directly to one hexadecimal digit.

For binary-to-hex conversion, group from the right into sets of four. Add leading zeros to the leftmost group if it is short. Convert each group separately, preserving the order of the groups.

BINARY TO HEXADECIMAL | TWO FOUR-BIT GROUPS

HIGHER GROUP

1010

↓

8 + 2 = 10

A

LOWER GROUP

1101

↓

8 + 4 + 1 = 13

D

1010 1101₂ = AD₁₆. Check in decimal: 10 × 16 + 13 = 173.

For 101101₂, group as 10 | 1101, then pad the first group to 0010 | 1101. The result is 2D₁₆. Grouping from the left without preserving the right-aligned place values can give the wrong answer.

10 | HEXADECIMAL BACK TO BINARY

Replace each hexadecimal digit with its four-bit binary pattern. Keep the digits in the same order. Using four bits for every group preserves its position, including zeros inside the full number.

Hex digitFour-bit representationWhy the width matters
30011Represents the higher group.
00000Preserves an entire zero-valued middle group.
A1010Represents ten in the lower group.

30A₁₆ becomes 0011 0000 1010₂. If a minimum-width answer is allowed, only the leading zeros of the complete number can be omitted: 1100001010₂. Removing the middle group of four zeros changes the value.

You do not need to convert the whole number to decimal first. The four-bit relationship gives a direct method in both directions.

11 | USE A CONVERSION AND WORKING CHECKER

Choose the input base and enter a non-negative integer. The checker displays the equivalent decimal, binary and hexadecimal forms and shows place-value or repeated-division working. It also groups binary into four-bit blocks.

For a manageable display, this activity accepts values from 0 to 65535: up to sixteen binary digits, four hexadecimal digits or five decimal digits within that range. This is an activity limit, not a claim that the IB syllabus or number systems stop at sixteen bits.

For binary and hexadecimal, you may include spaces between groups. Type only the digits, without prefixes such as 0b or 0x or a written subscript. Leading zeros are accepted within the stated width.

12 | SAME BITS, MORE COMPACT NOTATION

Hexadecimal is useful because a long binary pattern can be written with fewer symbols while keeping the direct four-bit relationship. Programmers may encounter hexadecimal when reading memory-related values, debugging output or colour codes.

The compact notation is for people and tools. Writing a bit pattern as hexadecimal does not, by itself, compress the underlying data or make the hardware process it faster. A byte written as 11111111₂ and FF₁₆ still describes the same eight-bit pattern.

For example, a common RGB colour notation #00FF80 specifies three components using two hex digits each. In that convention, red is 00 = 0, green FF = 255 and blue 80 = 128. The meaning comes from the agreed colour format, not from hexadecimal alone.

Likewise, whether a pattern is an integer, an address or part of some other encoding depends on context. The base tells you how to interpret the numeral, not every meaning an application assigns to its bits.

13 | WIDTH, RANGE AND VALID DIGITS

An unsigned field with n bits has 2ⁿ possible patterns, representing values from 0 to 2ⁿ − 1 when used as an ordinary non-negative integer. Eight bits therefore allow 0 to 255, not 1 to 256.

Each additional bit doubles the number of possible patterns. Two hexadecimal digits also describe 16² = 256 possible combinations, matching eight bits. Four hexadecimal digits match sixteen bits.

Check the allowed digits before converting. 10201 is not a valid binary numeral because binary has no digit 2. 3G is not valid hexadecimal because G is not among 0–9 and A–F.

A pattern such as 11111111 can mean 255 unsigned, but another representation can interpret it differently. Do not assume a signed interpretation unless its rule and width have been specified.

RepresentationAllowed digit valuesInteger place values from the right
Decimal, base 100–91, 10, 100, 1000, …
Binary, base 20–11, 2, 4, 8, 16, …
Hexadecimal, base 160–9, A–F1, 16, 256, 4096, …

14 | COMMON CONVERSION ERRORS

MistakeCorrection
11010₂ is read as the decimal numeral eleven thousand and ten.Apply binary place values: 16 + 8 + 2 = 26.
A is treated as two separate hex digits 1 and 0.A is one digit with value ten.
Repeated-division remainders are read top to bottom.Read the last remainder first.
Binary groups are made from the left without padding.Group from the right and pad only the leftmost short group.
A middle 0000 group is deleted during hex conversion.Keep every four-bit group; internal zeros affect place value.
Eight bits have a maximum unsigned value of 256.There are 256 patterns, with values 0 through 255.
Hexadecimal automatically compresses the stored byte.It is compact notation for the same bit pattern.

For describe the representation, identify the base, allowed digits and positional weights. For conversions, show the contributions, remainders or four-bit groups so someone can follow and check your method.

Try converting 93₁₀ to binary and hex, then reverse both conversions. Use the Questions tab to practise with different values rather than memorising one worked example.

MATCH THE REPRESENTATION TERM TO ITS MEANING

Terminology

Terminology

Integer

A whole-number value; this lesson’s worked conversions focus on non-negative integers.

Numeral

A written representation of a number in a particular notation.

Base

The number of digit values used by a positional number system.

Decimal

Base 10 notation using digits 0–9.

Binary

Base 2 notation using digits 0 and 1.

Hexadecimal

Base 16 notation using digits 0–9 and A–F.

Digit

A symbol representing one allowed value in a position.

Place value

The weight associated with a digit’s position in a numeral.

Bit

A binary digit.

Byte

A group of eight bits.

Nibble

A group of four bits.

Power

An exponent indicating repeated multiplication of a base.

Most significant position

The highest-weight position in the represented field.

Least significant position

The lowest-weight position, at the right of these integer representations.

Leading zero

A zero placed before the significant digits without changing a non-negative integer’s value.

Width

The specified number of positions used for a representation.

Unsigned representation

Interpreting a bit field as an ordinary non-negative integer.

Range

The set of values representable under a specified rule and width.

Quotient

The whole-number result used when repeatedly dividing an integer in this method.

Remainder

The amount left after whole-number division.

Repeated division

A conversion method recording remainders when dividing successively by the target base.

Binary grouping

Organising binary digits into right-aligned four-bit groups for hexadecimal conversion.

Hex digit A

The single hexadecimal digit with decimal value ten.

Hex digit F

The single hexadecimal digit with decimal value fifteen.

Subscript base label

A notation such as ₂ or ₁₆ indicating the number system.

Encoding convention

An agreed rule assigning meaning to a represented pattern.

Questions

Questions

CHECK YOUR UNDERSTANDING

Select all correct choices. Each exact set earns one point.

1. Which statements correctly compare number bases?
2. What decimal value does 00011010₂ represent as unsigned?
3. Which binary place values contribute to 101101₂?
4. Which hexadecimal digit has decimal value ten?
5. What is 2AF₁₆ in decimal?
6. Which statements about repeated division are correct?
7. What hexadecimal numeral matches 1010 1101₂?
8. Which correctly describe 30A₁₆?
9. Which are true for an unsigned eight-bit field?
10. Which statements are accurate?

EXPLAIN AND COMPARE

Write your answers before revealing each sample.

1. Describe binary and hexadecimal as positional systems.

2. Convert 101101₂ to decimal and show the method.

3. Convert 93₁₀ to eight-bit binary and hexadecimal.

4. Convert 2AF₁₆ to decimal and show place-value working.

5. Describe repeated division for decimal-to-binary conversion.

6. Describe a direct binary-to-hexadecimal method.

7. Convert 30A₁₆ to binary and explain why the middle zeros matter.

8. Explain why an unsigned eight-bit field stops at 255.

9. Describe the role of leading zeros and width.

10. Explain why hexadecimal is useful but does not itself compress binary data.

SHOW IT | A DEBUGGING REPORT

A tool displays an unsigned byte as B6 in hexadecimal. Write its eight-bit binary representation and decimal value, showing the grouping and place-value working. Then describe why hexadecimal helps a person read the pattern without reducing the number of bits in the byte.

Flashcards

Flashcards

Click to flip. Select the ideas you need to revisit.

0 cards selected for revision.

    Selections are kept while this page is open.

    Workbook

    Workbook

    COMING SOON

    The workbook for A1.2.1 Principal Methods of Representing Data is coming soon. Complete the matching task and written questions in your exercise book.