Zum Inhalt springen

English:Binary, hexadecimal and image representation - AI Year 10

Aus MOOCsWiki Staging
aiMOOC-Siegel aiMOOC

Binary, hexadecimal and image representation - AI Year 10

QR-Code



Introduction

A colour wheel surrounded by diagrams of red green and blue subpixels
RGB channels can encode many colours. This is a vector illustration of colour mixing, not our invented raster dataset or a trained vision model.

Read binary and hexadecimal as different representations of a value, calculate raw image storage with stated assumptions, and investigate how encoded image conditions affect a simple decision rule. Work with synthetic grids, not photographs of pupils. The original Python examples were actually executed; the image probes use transparent rules and do not train or certify an AI model. This is an editorial Year 10 route linked to common GCSE Computer Science foundations.


One value in several representations

A bit has two possible values, zero and one. In an unsigned binary number, each position has twice the place value of the position immediately to its right. For eight bits, the place values from left to right are 128, 64, 32, 16, 8, 4, 2 and 1. A zero contributes nothing at that position. Leading zeroes can preserve a declared width without changing the numerical value. The string 00101101 and the shorter string 101101 both represent decimal forty-five when interpreted as unsigned binary.

Trace 101101 using place values 32, 16, 8, 4, 2 and 1. The ones select 32, 8, 4 and 1, so the sum is 45. To convert decimal forty-five back, take 32, leave 13, take 8, leave 5, take 4, leave 1, then take 1. The positions for 16 and 2 stay zero. A second method repeatedly divides by two and reads the remainders in reverse; both methods must agree about place order.

Hexadecimal has sixteen digit values, written 0 through 9 and A through F. A means ten, B eleven, C twelve, D thirteen, E fourteen and F fifteen. Each hexadecimal digit corresponds to four binary positions. Pad 101101 on the left to 0010 1101; the groups are 2 and D, so the hexadecimal representation is 2D. Check it in base sixteen: two sixteens plus thirteen equals forty-five. Do not read the characters 2D as decimal twenty followed by a letter or as evidence that the value changed.

Representation of the same unsigned value Written form Check
Decimal 45 Four tens and five units
Binary 00101101 32 plus 8 plus 4 plus 1
Hexadecimal 2D Two sixteens plus thirteen

CS50's Hexadecimal short supports grouping four bits into one hexadecimal digit. Pause to work through a fresh conversion yourself. The course supplies its own examples, program and solutions; the video is external supporting material and does not replace an explanation or demonstrate your own competence.

An unsigned byte has eight bits and 256 possible patterns, representing integers from zero to 255 under this interpretation. The greatest value is 128 plus 64 plus 32 plus 16 plus 8 plus 4 plus 2 plus 1, which is 255. The count of patterns is one greater because zero is included. Decimal 256 cannot fit into this unsigned eight-bit contract. Reject it, use a wider representation, or declare another appropriate policy; do not silently discard a leading bit and pretend the value was preserved.

The same pattern may mean different things under different declared encodings. Decimal 65, binary 01000001 and hexadecimal 41 can identify the ASCII capital letter A when interpreted as an ASCII code. They could instead be a small integer measurement or a channel sample. A byte is a quantity of storage, not a universal promise of exactly one written character.

An ASCII reference table showing decimal hexadecimal and character values including control codes
Use the decimal hexadecimal and character columns as a reference. Some codes are controls rather than visible letters; this table does not cover every writing system.

In UTF-8, the program's separate single-code-point examples use one byte for U+0041, two for U+00E9, three for U+20AC and four for U+1F600. A user-perceived character can also involve more than one Unicode code point. These examples disprove the claim that every byte is one character; they are not a complete account of text segmentation. Read the accessible values in the written output rather than relying on tiny table labels or on a particular font rendering.

Try before checking: convert binary 00001111, 00010000, 10101010 and 11111111 into decimal and hexadecimal. Hint: split each into two four-bit groups. Partial check: 00001111 is decimal fifteen and hexadecimal 0F; 00010000 is decimal sixteen and hexadecimal 10. Keep the base label so that hexadecimal 10 is not mistaken for decimal ten.


Calculate raw pixels and separate the file format

A raster image represents a rectangular array of pixels. Width and height give the number of samples across and down. Colour depth describes how many bits are assigned per pixel under a declared representation. In a simple 24-bit RGB model, each pixel has eight bits for red, eight for green and eight for blue. Each channel takes one of 256 integer values. The colour wheel illustrates the channel idea; its own source is SVG vector data, so its downloaded file size must not be calculated as if it were our raw raster.

The basic calculation, before compression, headers, metadata, palettes, row padding or other format overhead, is:

B=w×h×d

Here B is the number of raw sample bits, w the width in pixels, h the height in pixels and d the bits per pixel. Divide by eight when those bits fill complete bytes. Otherwise round up if the entire stream is tightly packed into whole bytes. If a format aligns every row separately, round each row up first; those two assumptions can give different answers.

For the source example, width one hundred, height eighty and depth twenty-four give one hundred times eighty times twenty-four, which is 192,000 bits. Dividing by eight gives 24,000 bytes of raw RGB samples. That is 24 decimal kilobytes using one thousand bytes per kB, or 23.4375 KiB using 1024 bytes per KiB. State the convention. Neither number is a prediction of the complete PNG or JPEG file size.

100×80×248=24000

A second example, twenty by ten at eight bits per pixel, has two hundred pixels and 1,600 sample bits, or 200 bytes. Eight-bit greyscale can represent 256 sample levels in this simplified model. An indexed-colour format could use an eight-bit palette index with additional palette information; eight bits per pixel does not automatically mean eight red bits, eight green bits and eight blue bits.

Width by height Depth Raw sample bits Tightly packed whole bytes
100 by 80 24 192000 24000
20 by 10 8 1600 200
101 by 3 1 303 38

The third row is a boundary test. The whole stream has 303 bits and needs 38 whole bytes if packed without per-row alignment. If each 101-bit row starts at a byte boundary, each row needs thirteen bytes, so three rows need 39 bytes before any further overhead. This is a comparison of two declared packing models, not a claim about every real image format. It exposes why dividing and discarding a remainder would undercount storage.

File formats add their own structures. PNG uses lossless compression and stores information beyond raw samples; a PNG file need not equal width times height times depth divided by eight. Compression depends on sample patterns and the encoding process as well as dimensions. A small or noisy image can have proportionally substantial overhead or poor compression. Increasing width while retaining height and depth doubles the simple raw sample total, but does not guarantee exactly double the compressed file size. Lossy compression may change sample values and visible details; lossless means the encoded samples can be recovered, not that every photograph becomes tiny.

Two original RGB pixels give another byte-level check. Red is channel values 255, zero, zero; a second pixel is zero, 255, 128. Concatenate those six bytes in declared red-green-blue order to obtain hexadecimal FF000000FF80. The six-byte sequence is raw sample data only. It contains no image header, dimensions, colour profile or file signature and is not itself a complete viewable PNG file.

CodeAI's How Computers Work: Binary and Data connects representations to digital media. Use the written worked calculations to check the meaning and unit of every answer. Do not infer a file format, text encoding or trained model merely because some data consists of bytes.

Your turn: calculate the raw RGB samples for a two hundred by eighty image at twenty-four bits per pixel, and compare with the source example. Hint: change only width. Partial check: the pixel count doubles to sixteen thousand, so raw sample storage doubles to 48,000 bytes under the same assumptions. Explain what is still unknown about an actual saved compressed file.


Probe image conditions and keep evidence honest

Encoded pixels are the input to many image systems, but a numerical decision is not evidence that a system recognises an object as a person does. A learned model can rely on irrelevant background or lighting correlations. First investigate this risk using two deliberately simple rules on an original three by three greyscale grid. No model is trained, no camera is connected and no identifiable photographs are used.

The base grid has rows sixteen, 192, sixteen; sixteen, 192, sixteen; and sixteen, 192, 192. The four high samples form an invented L-shaped pattern. We declare that the pattern remains present in each of four authored positive test cases. A centre rule outputs one when the centre sample is at least 128. A corner rule outputs one when the top-left sample is at least 128. Those thresholds are transparent hand-written rules, not fitted parameters or a production object detector.

Change one condition relative to the base each time. The background case changes the background samples from sixteen to 224 while retaining the four pattern samples at 192. The dim case halves every base sample, giving eight and 96. The rotation case rotates the base grid ninety degrees clockwise without changing its values. It is an exact array rotation, not a simulation of perspective, a real camera angle or natural lighting physics.

Authored condition Centre sample Top-left sample Centre rule Corner rule
Base 192 16 1 0
Background changed 192 224 1 1
All samples halved 96 8 0 0
Base rotated ninety degrees 192 16 1 0

The corner rule changes its output when only the background changes, so its output depends on an irrelevant feature for the intended pattern task. In the brighter-background case it happens to output the declared positive label, but that isolated success does not show pattern recognition. The centre rule stays positive in that case yet fails the dim case, although the authored shape remains present. Both rules return unchanged outputs under this one rotation; that is not evidence of robustness to every angle, scale, occlusion or different pattern.

The complete original program below was executed. The conversion and storage functions enforce bounded teaching contracts, reject incompatible types and preserve meaningful boundary cases. The last section constructs the four image probes and prints the actual rule outputs. It also prints the UTF-8 byte counts and the raw two-pixel RGB sequence. It creates no formal image file and makes no external AI call.

"""Original bounded representation examples and synthetic image-rule probes."""
import json


def encode_byte(value):
    if type(value) is not int or not 0 <= value <= 255:
        raise ValueError("Expected an unsigned byte integer")
    return dict(decimal=value, binary=format(value, "08b"), hexadecimal=format(value, "02X"))


def binary_value(text):
    if not isinstance(text, str) or not 1 <= len(text) <= 8 or any(c not in "01" for c in text):
        raise ValueError("Expected one to eight binary digits")
    result = 0
    for digit in text:
        result = 2 * result + int(digit)
    return result


def storage(width, height, depth):
    if any(type(v) is not int or not 1 <= v <= 4096 for v in [width, height]):
        raise ValueError("Expected bounded positive dimensions")
    if type(depth) is not int or depth not in [1, 8, 24, 32]:
        raise ValueError("Unsupported teaching bit depth")
    bits = width * height * depth
    return dict(bits=bits, tightly_packed_bytes=(bits + 7) // 8,
                byte_aligned_rows_bytes=height * ((width * depth + 7) // 8))


def checked_grid(grid):
    if not isinstance(grid, list) or len(grid) != 3:
        raise ValueError("Expected a three by three grid")
    if any(not isinstance(row, list) or len(row) != 3 for row in grid):
        raise ValueError("Expected three values per row")
    if any(type(v) is not int or not 0 <= v <= 255 for row in grid for v in row):
        raise ValueError("Expected unsigned byte samples")


def image_rules(grid):
    checked_grid(grid)
    return dict(centre_rule=int(grid[1][1] >= 128), corner_rule=int(grid[0][0] >= 128))


def rotate_clockwise(grid):
    checked_grid(grid)
    return [list(row) for row in zip(*grid[::-1])]


def demonstrate():
    base = [[16,192,16], [16,192,16], [16,192,192]]
    background = [[224 if v == 16 else v for v in row] for row in base]
    dim = [[v // 2 for v in row] for row in base]
    rotated = rotate_clockwise(base)
    names = ["base", "changed_background", "dimmed", "rotated_90_clockwise"]
    tests = [dict(condition=name, grid=grid, declared_pattern_present=True,
                  prediction=image_rules(grid)) for name, grid in zip(names, [base,background,dim,rotated])]
    text_cases = [dict(code_point=format(v, "04X"), utf8_hex=chr(v).encode("utf-8").hex().upper(),
                       byte_count=len(chr(v).encode("utf-8"))) for v in [65,233,8364,128512]]
    rgb = bytes([255,0,0,0,255,128])
    return dict(conversions=[encode_byte(v) for v in [0,1,10,15,16,45,127,128,170,255]],
                source_binary=binary_value("101101"), source_storage=storage(100,80,24),
                second_storage=storage(20,10,8), padding_boundary=storage(101,3,1),
                raw_rgb_hex=rgb.hex().upper(), raw_rgb_bytes=len(rgb), text_cases=text_cases,
                image_tests=tests, model_trained=False, real_camera_test=False,
                invented_samples=True, formal_image_file_written=False)


if __name__ == "__main__":
    print(json.dumps(demonstrate(), indent=2))

Compare expected and actual outputs in a log with condition, source of data, intended label, rule output, error type and limitation. The source here is explicitly authored synthetic values, not measured camera performance. Four positive examples cannot estimate false positives or establish overall accuracy on real images. Add properly defined negative examples and a representative independent test set before evaluating a real model. Record any tuning separately so evaluation data is not silently reused for choosing the rule.

A real non-identifying image investigation could use permissioned photographs of manufactured washers or drawn geometric symbols. Prepare a matrix with separate changes in lighting, camera angle, background, focus and compression quality. Keep other conditions controlled where possible, document combined effects where not, and decide what expected result means. Use school-approved data and tools; avoid pupil faces, biometrics, names and private photos. A supervised test plan is a proposed next step, not evidence that this program has performed it.

For transfer to reading plant-pot symbols in a greenhouse, revisit the label definition, image rights, illumination, camera distance, backgrounds, confusing symbols and safe fallback. A threshold that worked for invented samples is not automatically suitable. A low raw byte count says nothing about a model's fairness, usefulness or understanding. Human review should remain available when the image conditions fall outside the checked scope.

Independent practice: convert decimal zero, one, ten, fifteen, sixteen, forty-five, 127, 128, 170 and 255 to eight-bit binary and two-digit hexadecimal. Attempt all ten before opening the Learning Check solution. The editorial target is at least eight correct pairs out of ten plus both raw-storage examples correct; it is a course exercise target, not a GCSE award or proof of all subject competence.


Interactive Tasks


Quiz: Test Your Knowledge

What is the decimal value of unsigned binary 101101? (45) (!41) (!53) (!101101)



Which hexadecimal representation has decimal value forty-five? (2D) (!45) (!D2) (!2F)



How many patterns can eight bits represent? (256) (!255) (!128) (!8)



Which decimal value is outside the unsigned eight-bit range? (256) (!255) (!128) (!0)



What is the raw sample byte count for 100 by 80 pixels at 24 bits per pixel? (24000) (!192000) (!8000) (!3000)



What is the raw sample byte count for 20 by 10 pixels at 8 bits per pixel? (200) (!1600) (!20) (!10)



Why can the actual PNG file size differ from a raw pixel calculation? (It includes format structures and compressed image data) (!Every PNG discards half the pixels) (!Pixels have no encoded values) (!All images have the same file size)



Which example disproves a universal one-byte-per-character claim? (A UTF-8 euro code point uses three bytes) (!The ASCII letter A uses one byte) (!A byte contains eight bits) (!A binary zero can be stored)



What does the corner-rule change under a new background demonstrate? (Dependence on background rather than evidence of pattern recognition) (!Successful training of a vision model) (!Guaranteed robustness to every camera angle) (!A change from binary to hexadecimal)



What evidence was actually produced by the image program? (Outputs of two hand-written rules on four synthetic positive grids) (!A trained neural network on pupil photographs) (!Certified camera accuracy under every condition) (!A complete compressed PNG image file)





Memory Game

Bit A position with one of two values
Byte A group of eight bits
Hexadecimal A base-sixteen representation
Pixel A sample in a raster image array
Depth Bits assigned per pixel under a declared model
Encoding A rule giving stored patterns a defined interpretation





Drag and Drop

Binary 101101 Decimal forty-five
Hexadecimal 2D Two sixteens plus thirteen
Raw 24-bit RGB Three eight-bit channel samples per pixel
Changed background A check for reliance on irrelevant surroundings
Missing file assumptions A reason to separate raw samples from complete file size





Crossword Puzzle

BINARY Representation using base two
HEXADECIMAL Representation using base sixteen
PIXEL One sample in a raster grid
DEPTH Number of bits per pixel in a declared representation
ENCODING Rules for interpreting stored patterns
PADDING Extra alignment storage that can change byte totals





LearningApps

Optional extra practice. Choose an appropriate activity with your teacher. If the external collection is unavailable, use the native activities and independent tasks in this course.


Cloze Text

Complete the explanation.
A binary place has a weight based on powers of

. Four binary positions correspond to one

digit. The unsigned eight-bit maximum is

. A byte contains eight

. Raster width times height gives the number of

. The raw bit total also depends on colour

. A tightly packed stream with a partial byte must round

. A compressed file can contain additional

. UTF-8 does not use one byte for every

. The corner rule can depend on the

. The four image probes were

. Their outputs do not establish real-camera

.



Open Tasks


Easy

  1. Trace binary place values: Trace binary 101101 using place values and explain why leading zeroes do not change its unsigned value.
  2. Cross the hexadecimal boundary: Convert decimal fifteen and sixteen to eight-bit binary and two-digit hexadecimal. Label the bases.
  3. Calculate raw RGB storage: Calculate the raw sample bits and bytes for 100 by 80 pixels at twenty-four bits per pixel, stating excluded overhead.
  4. Read the dimmed image probe: Read the condition table and identify the centre sample and both rule outputs after dimming.


Standard

  1. Complete ten representation pairs: Complete the ten conversion pairs in the final teaching chapter before checking them. Explain one conversion by grouping four bits.
  2. Compare two raw image calculations: Calculate raw sample storage for twenty by ten at eight bits per pixel and two hundred by eighty at twenty-four bits per pixel. State your byte convention.
  3. Distinguish UTF8 bytes and characters: Explain why a byte need not be one written character, using two actual UTF-8 examples and the distinction between code points and perceived characters.
  4. Identify a background shortcut: Compare the base and changed-background grids. Explain why the corner rule's isolated positive result does not prove pattern recognition.


Advanced

  1. Compare row and stream packing: Compare tightly packed and separately byte-aligned rows for 101 by three one-bit pixels. Show both byte totals and avoid claiming a universal file format.
  2. Design controlled washer image tests: Design a permissioned washer-image test matrix that varies lighting, camera angle, background and compression separately. Specify labels controls expected evidence and fallback.
  3. Critique positive only image evidence: Critique a claim that four positive synthetic tests establish a vision model's accuracy. Add negative cases independent evaluation and a record of tuning.
  4. Transfer to greenhouse symbols: Transfer the investigation to greenhouse symbols. Explain renewed checks of image rights label meaning conditions representation and review, and distinguish a plan from an executed real-camera test.



Learning Check

  1. Check ten unsigned conversion pairs: Convert the ten decimal practice values to eight-bit binary and two-digit hexadecimal, then use the declared exercise target.
  2. Check both raw storage examples: Calculate both source storage examples and explain why they are not complete file-size predictions.
  3. Resolve a packing boundary: Resolve the one-bit row-alignment boundary.
  4. Interpret text and RGB bytes: Use actual text and pixel byte examples to diagnose the interpretation claim.
  5. Interpret four image rule probes: Interpret all four executed image-rule probes without claiming a trained model.
  6. Design an evidence honest transfer: Propose a safe transfer and identify missing evidence.


Worked checks and assessment guidance

  1. The checked pairs are zero: 00000000 and 00; one: 00000001 and 01; ten: 00001010 and 0A; fifteen: 00001111 and 0F; sixteen: 00010000 and 10; forty-five: 00101101 and 2D; 127: 01111111 and 7F; 128: 10000000 and 80; 170: 10101010 and AA; 255: 11111111 and FF. Count a pair correct only when both forms represent the given value at the requested widths. Eight correct pairs is this editorial exercise target; correct both separate storage cases too. It does not award a qualification.
  2. One hundred times eighty times twenty-four gives 192000 bits and 24000 bytes. Twenty times ten times eight gives 1600 bits and 200 bytes. These are raw samples under the declared model. Headers metadata palettes row alignment compression and other format rules need separate treatment; do not guarantee those exact saved-file sizes.
  3. 101 times three times one is 303 bits. Tightly packing the whole stream needs ceiling of 303 divided by eight, or 38 bytes. Byte-aligning each 101-bit row needs thirteen bytes per row, so 39 bytes. Both exclude further overhead and describe explicit packing models. Rounding down to 37 bytes loses required bits.
  4. The separate UTF-8 code points U+0041 U+00E9 U+20AC and U+1F600 use one two three and four bytes, with hexadecimal 41 C3A9 E282AC and F09F9880. A perceived character may involve multiple code points. Raw RGB pixels red 255 zero zero and zero 255 128 concatenate to FF000000FF80, six bytes. Interpretation requires an encoding and channel order; these bytes alone are not a complete image file.
  5. Base outputs are centre one corner zero. Changing only the background yields one and one, so the corner rule depends on background. Halving all samples yields zero and zero even though the declared pattern remains present. The ninety-degree rotation yields one and zero, unchanged for this case only. The program executes two fixed rules on synthetic positive grids, with no model training camera measurements or general accuracy estimate.
  6. For permissioned non-identifying greenhouse symbols, redefine the labels and check image rights camera distance lighting background confusing shapes and compression. Use controlled condition comparisons negative and positive examples and an independent evaluation set after tuning. Keep appropriate human review. Report the classroom grid execution as executed synthetic evidence and the camera plan as proposed; neither certifies deployed performance.


Learning evidence

Keep ten labelled conversion pairs with the exercise tally, two raw-storage calculations with units and exclusions, the row-alignment boundary and byte-encoding examples. Add the executed grid table, expected versus actual outputs, changed-condition log and limitations. Preserve permission and provenance checks for any proposed new images. Separate raw samples from a file format, a hand-written rule from a trained model, and a test plan from real-camera evidence.


OER and Wikipedia

DfE GCSE Computer Science subject content, updated 31 March 2025, number representation graphics and data capacity sections inspected 15 November 2026. The ordered Year 10 AI enrichment activities and eight-of-ten exercise target are editorial, not additional statutory requirements or an exam-board specification.

Unicode Consortium UTF FAQ, the encoding-form and byte-count explanation inspected 15 November 2026. The original code executes four separate code-point examples; it does not implement complete grapheme segmentation.

W3C PNG specification, Third Edition, the abstract and sample/format distinction inspected 15 November 2026. This course's simple packing arithmetic is explicitly not a complete PNG serializer or saved-file predictor. Python built-in types documentation supplies the relevant numeric string and bytes API reference; our bounded program and data are original.

RGB color wheel pixel 5.svg, László Németh, CC0, unchanged vector illustration. ASCII-Table-wide.svg, ASCII-Table.svg: ZZT32 derivative work: YUFENG HUANG, public domain, unchanged. Exact file pages metadata retained preview bytes and native image rendering checked; previews visually inspected. The table includes controls and the wheel is not our raster dataset. Written examples provide colour-independent and readable alternatives.

https://www.youtube.com/watch?v=u_atXp-NF6w — CS50: Hexadecimal - CS50 Shorts. https://www.youtube.com/watch?v=USCBCmwMCDA — CodeAI: How Computers Work: Binary and Data. Verified metadata embedding availability and retained previews checked and visually inspected. External unchanged embeds imply no transcript copying endorsement or relicensing. All required methods are explained in the written course.

All sample grids values thresholds RGB bytes exercises tests and transfer scenarios are original synthetic teaching constructions. The program was executed without model training external AI or personal learner data. Four positive probes are not a real-world accuracy study. Author checks are not independent expert certification.


Linked learning areas


aiMOOC Projects



Schulfach+




aiMOOCs



aiMOOC Projekte









MOOCwiki · Deutsch

Nach dem Lernen ist vor dem Lernen

Entdecke direkt den nächsten Lernkurs. Weitere Inhalte erscheinen, wenn Du weiter nach unten scrollst.

Zur MOOCwiki-Hauptseite

Mediathek

Suche verfeinern

Dein Lernplan bestimmt, was oben steht. Alle anderen Inhalte bleiben erreichbar. Seitenaufrufe beeinflussen die Auswahl nicht.

Inhalte werden geladen ...

Mediathek wird aus dem Wiki geladen ...