Skip to content

← Data and representation

How Computers Store Everything

Unit 2 · Data and representation

Hide the stories, facts, photos, activities and interactives, for revising before an exam
In this unit 10 sections
  1. Binary, both ways
  2. Adding in binary
  3. Text is numbers
  4. Unicode: every script in the world
  5. Old Nepali files: Preeti
  6. Colors from numbers
  7. Raster and vector pictures
  8. Sound as samples
  9. In short
  10. Exercise

Send a message to a friend: “नमस्ते! See you at the Bhaktapur Durbar Square at 4.” Add a photo of the pagodas and a voice note of the temple bells. In less than a second it has all arrived on your friend’s phone, in the right letters, the right colors and the right sounds.

In Grade 6 you learned that a computer keeps everything as bits, 0s and 1s, and you counted in binary. But a letter is not a number. Neither is the red of a rhododendron, or the sound of a bell. So how does a computer keep them?

The answer is the big idea of this unit: everything is turned into numbers first. People agree on a rule for each kind of thing: which number stands for which letter, how a color is written as numbers, how a sound is measured. Then the numbers are stored in binary. In this unit you will add in binary, see the numbers behind English and Nepali letters, find out why old Nepali files turn into nonsense and fix one, mix colors from numbers, and turn a sound into samples.

Binary, both ways

First, a quick reminder from Grade 6. In binary, each place is worth twice the place to its right:

128 64 32 16 8 4 2 1

To read a binary number, add the place values that have a 1 under them: 10010110 = 128 + 16 + 4 + 2 = 150. To write a number in binary, you took away the biggest place value that fits, then the next, and so on.

Here is a second way to write a number in binary, which needs no list of place values: keep halving.

  1. Divide the number by 2. Write down the remainder (what is left over): it is always 0 or 1.
  2. Divide the answer by 2 again, and write down that remainder.
  3. Carry on until the answer is 0.
  4. Read the remainders from the last one to the first: that is the number in binary.

Why does it work? The first remainder tells you whether the number is odd or even, and that is exactly the ones place. Halving then moves every bit one place to the right, so the next remainder is the twos place, and so on. You collect the bits from the right-hand end first, which is why you read them backwards.

Try it

Check your conversions

Type a number from 0 to 255 in the box, and the bulbs show it in binary. Or tap the bulbs and read the number. Use it to check your answers, after you have worked them out on paper.

Binary
00000000
Number
0

0 = 0

Tap a bulb to switch it on (1) or off (0).

The left bit is off, so the number is 0 or more: the other bits add up as usual.

0 and then all 1s: 255, the biggest number 8 bits can show this way. Add 1 and it becomes 0.

Each bit that is on adds its place value to the number. A bit that is off adds nothing.

Adding 1: the bit worth 1 was off, so it simply came on.

Adding 1: the bits on the right that were on went off, and the next bit came on. That is a carry, like 9 + 1 = 10.

All 8 bits are on: 255, the biggest number 8 bits can show. To go higher you need one more bit.

Yes, that is one of the numbers to make. Now try another.

You made every number in the row.

A new pattern! Keep switching to find the others.

You have found that pattern already.

You found them all: 8 bits make 16 different patterns.

What is 10010110 in decimal?

Pick an answer to see why.

Adding in binary

You add binary numbers in columns, from the right, just as you add on paper in decimal. The only difference is that you run out of digits much sooner. In decimal, 7 + 5 = 12: you write 2 and carry 1 into the tens. In binary there are only four things that can happen in a column:

In the column Total In binary Write Carry
0 + 0 0 0 0 0
0 + 1 or 1 + 0 1 1 1 0
1 + 1 2 10 0 1
1 + 1 + a carried 1 3 11 1 1

That is the whole of binary addition. The last two rows are the ones to remember: 1 + 1 = 10 (write 0, carry 1), and 1 + 1 + 1 = 11 (write 1, carry 1).

Try it

Add two bytes

Tap the bits of the two numbers to change them. Press Add column by column and then Next column to see each column added, with its carry, from the right. Then try two numbers whose total is more than 255, such as 200 and 100.

1286432168421 1111 + 01001011
In decimal
45 + 30 = 75
Answer in 8 bits
75

Tap the bits to change the two numbers. Each column is added like on paper: 1 + 1 = 10, so write 0 and carry 1.

The answer, 75, needs 9 bits, but there are only 8. The extra 1 falls off the left end and is lost, so 8 bits show 75. This is overflow.

Column worth 256: 0 + 0 = 0. Write 0, nothing to carry.

Column worth 256: the bits add up to 1. Write 1, nothing to carry.

Column worth 256: 1 + 1 = 2, which is 10 in binary. Write 0, carry 1 to the next column.

Column worth 256: 1 + 1 + the carried 1 = 3, which is 11 in binary. Write 1, carry 1.

Overflow: when the answer doesn’t fit

A cricket scoreboard with only two digits for each batter would be fine until someone scored 100. Then it would show 00. The score hasn’t gone, but the board has no place to show it.

Computers have the same problem. A computer keeps each number in a fixed number of bits, often 8, 16, 32 or 64. If an answer needs more bits than that, the extra bit has nowhere to go and is lost. This is called overflow.

What is 1 + 1 + 1 in binary?

Pick an answer to see why.

An 8-bit computer adds 250 and 10. What does its byte hold?

Pick an answer to see why.

Text is numbers

Think of a token you get at a busy momo shop. Your order isn’t shouted across the room: it becomes a number, and the number is called out when it is ready. Computers do the same with letters. Every letter, digit, space and punctuation mark is given a number, called its character code, and the computer stores the number, in binary.

A character is any single symbol of text: A, a, 7, ?, a space, or क. For this to work, every computer has to use the same codes, or a message typed on one would come out as different letters on another. So people agreed on a table of codes.

ASCII

The first table used almost everywhere was ASCII, the American Standard Code for Information Interchange, first published in 1963 (small letters were added in 1967). It uses 7 bits, so it has 2 × 2 × 2 × 2 × 2 × 2 × 2 = 128 codes, numbered 0 to 127.

  • Codes 0 to 31, and 127, are control codes: they don’t print anything, but mean things like “start a new line” or “tab”.
  • Codes 32 to 126 are the 95 characters you can see: the space (32), punctuation, the digits 0 to 9 (48 to 57), the capital letters A to Z (65 to 90) and the small letters a to z (97 to 122).
32space33!34"35#36$37%38&39'40(41)42*43+44,45-46.47/48049150251352453554655756857958:59;60<61=62>63?64@65A66B67C68D69E70F71G72H73I74J75K76L77M78N79O80P81Q82R83S84T85U86V87W88X89Y90Z91[92\93]94^95_96`97a98b99c100d101e102f103g104h105i106j107k108l109m110n111o112p113q114r115s116t117u118v119w120x121y122z123{124|125}126~digitscapital letterssmall letters32space33!34"35#36$37%38&39'40(41)42*43+44,45-46.47/48049150251352453554655756857958:59;60<61=62>63?64@65A66B67C68D69E70F71G72H73I74J75K76L77M78N79O80P81Q82R83S84T85U86V87W88X89Y90Z91[92\93]94^95_96`97a98b99c100d101e102f103g104h105i106j107k108l109m110n111o112p113q114r115s116t117u118v119w120x121y122z123{124|125}126~digitscapital letterssmall letters
Figure 2.1 ASCII’s printable characters, codes 32 to 126. The code is above each character. Digits, capital letters and small letters each run in order, and each small letter’s code is its capital’s code plus 32: A is 65, a is 97.
An old printed chart: columns and rows of small boxes, each with a character and its bits, headed with 0s and 1s
Figure 2.2 The ASCII table of 1967, as printed in an American printer’s manual of the time. Each character’s 7 bits are read from its column (the first three bits) and its row (the last four). Photo: an unknown officer or employee of the United States Government, Public domain

So the word Hi is stored as two numbers: 72 for H and 105 for i. In binary: 1001000 1101001.

Try it

A character from its code

Seven bulbs, one ASCII code. The bulbs start at 65, the code for A. Switch one bulb at a time and watch the character change. Then type the code for a (97). Which single bulb is different between A and a?

Binary
1000001
Number
65
Character with this code
“A”

65 = 64 + 1

Tap a bulb to switch it on (1) or off (0).

The left bit is off, so the number is 0 or more: the other bits add up as usual.

0 and then all 1s: 127, the biggest number 7 bits can show this way. Add 1 and it becomes 0.

Each bit that is on adds its place value to the number. A bit that is off adds nothing.

Adding 1: the bit worth 1 was off, so it simply came on.

Adding 1: the bits on the right that were on went off, and the next bit came on. That is a carry, like 9 + 1 = 10.

All 7 bits are on: 127, the biggest number 7 bits can show. To go higher you need one more bit.

Yes, that is one of the numbers to make. Now try another.

You made every number in the row.

A new pattern! Keep switching to find the others.

You have found that pattern already.

You found them all: 7 bits make 16 different patterns.

Answer

In ASCII, B is 66. What is the code for b?

Pick an answer to see why.

Unicode: every script in the world

ASCII has room for English, and very little else. There is no é for French, no ñ for Spanish, and certainly no क or ङ. For years every country, and sometimes every company, made its own table of codes, each different. A file made with one table turned into nonsense with another.

In Grade 6 you met the answer: Unicode, one table of codes for every writing system in the world. Its first version came out in 1991. Its first 128 codes are exactly ASCII’s, so A is still 65; after them come the letters of every other script. Each character’s number is called its code point.

Character Script Code point
A Latin (English) 65
é Latin (French) 233
अ Devanagari 2309
क Devanagari 2325
० Devanagari digit zero 2406
中 Chinese (middle) 20013
😀 emoji 128512

Devanagari, the script of Nepali, Hindi, Sanskrit and Marathi, has the codes from 2304 to 2431, and a few more blocks elsewhere for rarer letters. Unicode’s Devanagari codes were based on an Indian standard, ISCII, so they follow the order of the Devanagari alphabet: अ आ इ ई… then क ख ग घ ङ…

How Nepali is stored

Unicode doesn’t give a separate code to every Nepali syllable you can write: there are thousands of them. Instead, it gives codes to the parts, and a syllable is stored as a few codes, in the order you say it:

  • a consonant, such as क (2325);
  • a vowel sign (मात्रा), such as ा (2366) or ि (2367), stored after the consonant it belongs to;
  • the halant (हलन्त), ◌् (2381), which joins a consonant to the next one to make a half letter or a conjunct.

So का is two codes, क then ◌ा, and क्ष is three: क, ◌्, ष.

किstored asक2325◌ि2367ि is drawn before क,but stored after itक्षstored asक2325◌्2381ष2359three codes; the fontjoins them into one letterकर्मstored asक2325र2352◌्2381म2350र् on top of म isstored before मकिstored asक2325◌ि2367ि is drawn before क,but stored after itक्षstored asक2325◌्2381ष2359three codes; the fontjoins them into one letterकर्मstored asक2325र2352◌्2381म2350र् on top of म isstored before म
Figure 2.3 Three Nepali syllables and the codes they are stored as. The codes are always in the order the syllable is said, even when the shape is drawn in another order: ि is drawn on the left of क but stored after it, and the reph (र् drawn on top of म in कर्म) is stored before म.

The shapes are the font’s job (below). The stored codes only say which sounds come in which order; the font decides that ि goes on the left, and that क + ् + ष is drawn as one letter, क्ष.

Try it

Every character is a number

Type anything, in English or Nepali, or pick a button. Each box shows one character and the number stored for it. How many numbers does नमस्ते need? Why more than its three syllables, न, म and स्ते?

न 2344 म 2350 स 2360 ◌् 2381 त 2340 ◌े 2375
Characters (numbers stored)
6

Type something, or pick one of the buttons.

Every English letter, digit, space and punctuation mark has its own number. A capital and a small letter have different numbers.

Every character, of every script, is stored as its own number.

A Nepali syllable is stored as several numbers: a letter, then its vowel sign or a halant (्) and the next letter.

Each English character is a number under 128, so it fits in one byte.

English characters take 1 byte each, but every Devanagari letter or sign takes 3 bytes: its number is over 2,047.

An emoji’s number is over 65,535, so it takes 4 bytes. Nepali letters take 3, English ones 1.

The bigger a character’s number, the more bytes it takes: 1, 2, 3 or 4.

Answer

How many bytes? UTF-8

In Grade 6 you read that one byte can hold one English letter, but that Nepali letters usually take more. Here is why.

A Unicode code point can be as big as 1,114,111, far more than one byte can hold (255). Storing every character in 4 bytes would work, but it would make every English text four times bigger. So most computers and nearly every website use a clever way of storing the code points, called UTF-8:

Code point Bytes in UTF-8 Examples
0 to 127 (ASCII) 1 A, a, 7, ?, space
128 to 2,047 2 é, ñ, Greek, Arabic
2,048 to 65,535 3 क, ा, ०, Chinese
65,536 and up 4 😀 and most emoji

The bigger the number, the more bytes it takes. Every Devanagari code is between 2,304 and 2,431, so each one takes 3 bytes. Namaste in English letters is 7 bytes; नमस्ते is 6 codes × 3 = 18 bytes.

Try it

Count the bytes

The small squares under each character are its bytes in UTF-8. Compare the English and the Nepali, then add an emoji.

N 78 a 97 m 109 a 97 s 115 t 116 e 101 ␣ 32 न 2344 म 2350 स 2360 ◌् 2381 त 2340 ◌े 2375
Characters (numbers stored)
14
Bytes in UTF-8
26

Type something, or pick one of the buttons.

Every English letter, digit, space and punctuation mark has its own number. A capital and a small letter have different numbers.

Every character, of every script, is stored as its own number.

A Nepali syllable is stored as several numbers: a letter, then its vowel sign or a halant (्) and the next letter.

Each English character is a number under 128, so it fits in one byte.

English characters take 1 byte each, but every Devanagari letter or sign takes 3 bytes: its number is over 2,047.

An emoji’s number is over 65,535, so it takes 4 bytes. Nepali letters take 3, English ones 1.

The bigger a character’s number, the more bytes it takes: 1, 2, 3 or 4.

Why does a text in Nepali take more bytes than the same length of text in English?

Pick an answer to see why.

Fonts

A code point says which character, not what it looks like. The shape is drawn by a font: a file with a drawing for each character it knows. The same codes, 2325 and 2366, can be drawn in many fonts, plain or fancy, thin or bold, and they still say का.

  • A Nepali Unicode font draws Devanagari, and also knows the rules for joining letters: put ि on the left, draw क + ् + ष as क्ष, put the reph on top.
  • If no font on a device has a shape for a code, the device shows an empty box, ☐, or a question mark. The text isn’t broken: the codes are all there. Install a font with the shapes, and it appears.
  • The drawings in a font are not stored as pixels but as outlines, so letters stay sharp at any size. You will see why below, in Raster and vector pictures.

A phone shows a message as ☐☐☐☐. What has most likely happened?

Pick an answer to see why.

Old Nepali files: Preeti

In Grade 6 you saw that text typed in the Preeti font is saved as English letters, so g]kfn shows as नेपाल only where the Preeti font is installed. Now you can see why it was made that way.

Before Unicode was everywhere, a computer’s text was one byte per character, with ASCII in the first 128 codes. There were no codes for Nepali at all. So font makers in Nepal did something clever: they made fonts that draw Nepali shapes in place of the English letters. The code for k (107) was still stored, but the Preeti font drew प for it. On that one computer, it looked perfect.

But the file holds only ASCII codes. To every other computer, and to every search and spell-checker, they are English letters. Many other fonts did the same thing with different maps (Kantipur, PCS Nepali, Sagarmatha, Himalb…), so a file typed in one of them is nonsense even in another of them.

Converting Preeti to Unicode

A converter is a program that turns an old Preeti text into real Unicode Nepali. It has to do more than swap one key for one letter, because Preeti was typed the way the shapes are drawn, not the way the codes must be stored:

  • ि is typed first. In Preeti you type l (ि) before the consonant, as you would write it: ls for कि. Unicode stores क first, then ि. The converter moves it.
  • The reph comes last. The र् that sits on top of a letter is typed after that letter, with {: wd{ is धर्म. Unicode stores र् before म. The converter moves it.
  • Some letters are two keys. In Preeti k is प, and k then m is फ; G is a half न, and G then f (ा) is the full न.

So a converter swaps every key for its shape, then moves the signs typed out of order into Unicode’s order. Then it is real Nepali, which any phone shows and any search finds.

Try it

Convert an old notice

This is what an old notice typed in Preeti really holds. Press Convert to Unicode, then look for सूचना in both. You can also paste Preeti text of your own into the box, convert it, and copy the result.

Converted: real Nepali letters (Unicode)
—
A search for सूचना finds it in the old file
no
…and in the converted text
—

These English letters are what an old Preeti file really holds. Press Convert to turn them into Nepali letters.

The converter swapped each key for its Nepali letter and put the signs typed out of order (ि, the reph र्) in their right places.

You changed the text. Press Convert again.

Copied. Paste it into any document or message: it is real Nepali text now.

Paste or type some Preeti text above.

How Nepali search and spell-check work

A search doesn’t look at shapes. It compares numbers: to find नेपाल, it looks for the codes 2344, 2375, 2346, 2366, 2354, one after another. That is why Preeti text can’t be found (its codes are English letters), and why the same word must be typed the same way to be found.

Nepali makes this harder in two ways:

  • Two spellings of one word. बिद्यालय and विद्यालय have different codes (ब and व). A search for one misses the other. The dictionary decides which spelling is right (विद्यालय), and a careful writer uses it.
  • Endings. घर, घरमा, घरको, घरहरूमा are one word with different endings. A good search knows the common endings and finds them all when you search for घर.

A spell-checker works with a long word list, and rules for the endings each word can take, so it doesn’t need to list घरमा and घरको separately. It takes each word you typed, finds the word underneath its ending, and checks it against the list. A word that isn’t there gets a red line. To suggest a correction, it looks in the list for words that differ by one or two letters: for बिद्यालय it finds विद्यालय. None of this can work on Preeti text, because its codes aren’t Nepali letters at all.

A search for विद्यालय doesn’t find a notice, though the notice shows विद्यालय on your screen. Which is the most likely reason?

Pick an answer to see why.

Colors from numbers

Look at a phone’s screen through a drop of water on the glass, or with a magnifying glass. In Grade 6 you saw that the picture is made of pixels. Look closer, and each pixel is really three tiny lights: one red, one green and one blue.

Rows of tiny red, green and blue lights on a black background, seen through a microscope
Figure 2.4 A phone’s screen under a microscope, magnified 200 times. Each pixel is made of tiny red, green and blue lights. (In this screen the lights are shared between neighboring pixels in a pattern; other screens have a red, green and blue light in every pixel.) Photo: Matthew Rollings at English Wikipedia, CC BY 3.0

Every color on a screen is made by mixing these three lights at different brightnesses. This is mixing light, not paint, and it works differently from the paint box at school:

  • red + green light = yellow;
  • red + blue = magenta (a pinkish purple);
  • green + blue = cyan (a sky blue);
  • all three at full brightness = white;
  • none at all = black: the screen gives no light there.

Each light’s brightness is stored as a number from 0 (off) to 255 (full): one byte. So a pixel’s color is three bytes, written as three numbers in the order red, green, blue. This is called RGB.

Color Red Green Blue
black 0 0 0
white 255 255 255
red 255 0 0
yellow 255 255 0
gray 128 128 128
orange 255 140 0

Try it

Mix colored light

Three lights, red, green and blue, shine on a black screen. Move the sliders, and watch what happens where they overlap. Then pick a color in the row of buttons and mix it: make your pixel match.

redgreenblueMix thisYour pixel
Mix:
Red byte
11111111
Green byte
10100000
Blue byte
00000000

Where two lights overlap, their light adds up: red and green make yellow. The pixel is 3 bytes: 255, 160, 0.

All three lights off, 0, 0, 0: black. A screen makes black by giving no light.

All three at full, 255, 255, 255: white. White light is all the colors together.

Red, green and blue equal: a gray. The same amount of each, but less than full.

Move the three sliders until your pixel matches the color above it.

That matches: 255, 160, 0. Now pick another color to mix.

You mixed every color from just red, green and blue light.

How many colors can a pixel show? Each of the three lights has 256 levels, so there are 256 × 256 × 256 = 16,777,216 colors: almost seventeen million. That is enough that the steps between neighboring colors are too small for your eyes to see.

Color pictures

A color picture is a grid of pixels, as in Grade 6, but now each pixel is 3 bytes (24 bits) instead of 1 bit.

Try it

A picture in color

Pick a color and paint. Count the bytes: the same 8 × 8 grid that took 8 bytes in black and white takes 192 bytes in color.

Paint:
Pixels
8 × 8 = 64
Bits
64 × 24 = 1,536
Bytes
64 × 3 = 192

Pick a color and tap or drag on the pixels. Each pixel is stored as three numbers: red, green and blue.

That pixel is stored as red 207, green 230, blue 245: 3 bytes, 24 bits.

That pixel is stored as red 242, green 183, blue 5: 3 bytes, 24 bits.

That pixel is stored as red 79, green 138, blue 60: 3 bytes, 24 bits.

That pixel is stored as red 47, green 107, blue 58: 3 bytes, 24 bits.

That pixel is stored as red 160, green 82, blue 45: 3 bytes, 24 bits.

That pixel is stored as red 255, green 255, blue 255: 3 bytes, 24 bits.

A pixel is stored as red 255, green 255, blue 0. What color is it?

Pick an answer to see why.

Raster and vector pictures

There are two quite different ways to keep a picture.

A raster picture (also called a bitmap) is what you have seen so far: a grid of pixels, with the color of every one stored. A photo is a raster picture. It can hold any detail, however messy: leaves, faces, clouds.

A vector picture stores instructions to draw shapes: “a circle, with its center here, this big, filled yellow”; “a line from this point to that point, 2 units thick, black”. To show it, the computer draws the shapes, at whatever size the screen needs. You did this in Grade 6 with the turtle: the blocks were a vector picture, and the turtle drew it.

Try it

The same logo, zoomed

The same small logo, kept two ways. Slide Zoom and watch both. Compare the sizes of the two files.

Raster: 128 × 128 pixels
Vector: 3 shapes
Raster file: pixels × 3 bytes
16,384 × 3 = 49,152 bytes
Vector file: the shapes as text
about 170 bytes
The vector file says: background: light blue circle: center 68, 30; radius 15; yellowtriangle: corners 2, 92 / 38, 38 / 74, 92; greentriangle: corners 36, 92 / 70, 50 / 98, 92; dark green

At normal size the two look the same. Slide Zoom to the right.

Zoomed in, the raster shows its square pixels. The vector is drawn again from its shapes at the new size, so its edges stay sharp.

The difference shows when you make a picture bigger. A raster picture has only the pixels it has: blow it up, and each pixel becomes a big square block, so edges look jagged. A vector picture is simply drawn again at the bigger size, so its edges stay sharp at any size, from a visiting card to a banner across the street.

Raster Vector
What is stored the color of every pixel shapes: lines, curves, circles, with their colors
Made bigger goes blocky stays sharp
File size grows with the number of pixels grows with the number of shapes
Good for photos, paintings, anything detailed and natural logos, icons, maps, diagrams, letters
Examples a phone photo, a scanned page a school’s logo, a font’s letters, the diagrams in this book

So which to use? A photo must be raster: there are no simple shapes in a face or a hillside. A logo should be vector: it is made of a few clean shapes, and it must look sharp on a small badge and a large signboard. The letters of a font are vector too, which is why text on a phone stays sharp however far you zoom in. Every drawing in this book is a vector picture.

The school wants its logo printed on a small ID card and on a large banner for the gate. How should the logo be kept?

Pick an answer to see why.

Sound as samples

Bang a madal, and its skin shakes back and forth very fast. It pushes the air, and waves of pressure travel to your ears. A microphone turns those waves into an electric signal that rises and falls the same way. Draw it, and you get a wavy line.

A wavy line is smooth: it has a value at every moment. A computer can only keep a list of numbers. So it measures the wave many times a second, and keeps each measurement as a number. Each measurement is a sample, and the whole process is called sampling.

Two choices decide how good the stored sound is:

  • Samples a second (the sample rate): how often the wave is measured. Too few, and quick wiggles in the wave, the high sounds, are missed.
  • Bits a sample: how exactly each measurement is kept. With 3 bits there are only 8 levels to choose from, so each sample is rounded to the nearest level and the sound comes out rough. With 16 bits there are 65,536 levels.

To play the sound back, the computer sends the numbers, one after another, at the same speed, to the speaker, which moves back and forth and makes the air wave again.

Try it

Sampling a sound

The gray line is a sound wave, 4 thousandths of a second of it. The red dots are the samples, and the blue steps are what is stored and played back. Change the number of samples a second and the bits a sample. Press Listen to hear a short tone stored that way.

04 thousandths of a second
Samples a second:
Bits a sample:
Levels
8
Bytes for 1 second
3,000
For 1 minute
176 KB

Only a few samples: the dots miss the wave’s wiggles, so the stored sound is rough.

Few bits, few levels: each sample is rounded to the nearest level, so the steps jump.

More samples and more levels: the steps follow the wave more closely, but each second takes more bytes.

44,100 samples a second, 16 bits each, as on a music CD: the steps are too small to see or hear.

What happens if a sound is stored with more samples a second and more bits a sample?

Pick an answer to see why.

In short

Exercise

Which is 22 in binary?

Pick an answer to see why.

What is 0110 + 0011 in binary?

Pick an answer to see why.

How many bytes does the word घर (घ and र) take in UTF-8?

Pick an answer to see why.

a.

Explain the meaning of these words: character code, ASCII, Unicode, code point, font, overflow, RGB, sample.

Answer
b.

Change into binary by halving, and check each answer by adding place values: i. 13 ii. 45 iii. 130 iv. 255

Answer
c.

Add these binary numbers. Check each answer in decimal.

  • i.0011 + 0100
  • ii.0111 + 0001
  • iii.1011 + 0110
  • iv.00111100 + 00011110
Answer
d.

An 8-bit computer adds 11110000 and 00100000.

  • i.What is the true answer, in binary and in decimal?
  • ii.What does the computer’s byte hold?
  • iii.What is this problem called, and how can a program avoid it?
Answer
e.

Use Figure 2.1 to decode this message: 75 97 116 104 109 97 110 100 117

Answer
f.

Why was Unicode needed when ASCII already existed? Give two reasons.

Answer
g.

The word किताब looks like it begins with ि. In what order are its codes stored, and why does it look different on the screen?

Answer
h.

Rita opens a notice her father typed in 2008 and sees ;"rgf. On her father’s old computer it showed सूचना.

  • i.Why does Rita see different letters?
  • ii.Why can’t she find the notice by searching for सूचना?
  • iii.How can she fix the file? What must she check after fixing it?
Answer
i.

How does a spell-checker decide that a Nepali word is wrong? Give one kind of mistake it can’t catch.

Answer
j.

Write the RGB numbers for: i. black ii. red iii. yellow iv. cyan. Explain why red and green light make yellow, when red and green paint don’t.

Answer
k.

A picture is 800 pixels across and 600 pixels down, with 3 bytes a pixel.

  • i.How many pixels does it have?
  • ii.How many bytes do the pixels need?
  • iii.About how many MB is that?
Answer
l.

Give three differences between raster and vector pictures. Which would you use for: i. a photo of your class ii. the logo of a cooperative iii. a map of the school’s fire exits to print on a large board?

Answer
m.

Explain how a sound is stored in a computer. What two choices decide how good the stored sound is, and what does each cost?

Answer
n.

A voice message is stored with 8,000 samples a second, 8 bits each, for one loudspeaker. How many bytes does a 30-second message take? How many KB?

Answer