কম্পিউটার বিজ্ঞান · বই 1 · শ্রেণি 1–9

Primary & Middle School Computer Science

এই বইটি এখনো বাংলা ভাষায় পাওয়া যায় না। সংস্করণ: English।

Primary & Middle School Computer Science · শ্রেণি 1–9

12Text, Pictures and Sound as Numbers

Lina sends a message to her cousin: “HI”. Her cousin’s phone, far away, shows the two letters a moment later. But no letter travelled along the cables: what travelled was sixteen bits, sixteen 0s and 1s. A computer keeps only bits, so a letter, a photo and a song must all become numbers first. This chapter shows how.

You already know

A bit is a choice between 0 and 1; a byte is eight bits and holds a whole number from 0 to 255; numbers can be written in binary (Chapter 11).

12.1 Every character has a number

Definition 12.1 (Character code)

A character code is the number given to a character (a letter, a digit, a sign, the space) by a code table, a table agreed by everyone, so that all computers turn the same character into the same number.

ABCDEFGHIJKLM
65666768697071727374757677
NOPQRSTUVWXYZ
78798081828384858687888990
small letters: a is 97, b is 98, …, z is 122 digits: 0 is 48, 1 is 49, …, 9 is 57 the space: 32

A word becomes a list of numbers, one for each character, and each number fits in one byte. “HI” is 72 and 73; in binary, on one byte each, it is 01001000 01001001: sixteen bits.

“HI” on its way: characters, then numbers, then bits.
“HI” on its way: characters, then numbers, then bits.

History — A table agreed by everyone

The table used here comes from the American code for exchanging information, known as ASCII, in its version of 1968. It gives numbers to the English letters, the digits, the signs and a few control codes, 128 characters in all. Later, a much larger table was made, with a number for every character of every alphabet, Chinese characters and emoji included; it keeps the same numbers for the characters of this small table.

12.2 A picture is a grid of pixels

Look at a screen through a magnifying glass: the picture is made of tiny squares, in rows and columns, each of one single colour.

Definition 12.2 (Pixel)

A pixel is one of the tiny squares, all of one colour, that make up a picture on a screen or in a file, arranged in rows and columns.

The simplest pictures are black and white: each pixel is black or white, so one bit is enough for it, 1 for black and 0 for white.

A smiley of 8 by 8 pixels and its 64 bits: 1 for a black pixel, 0 for a white one, one row of bits for each row of pixels.
A smiley of 8 by 8 pixels and its 64 bits: 1 for a black pixel, 0 for a white one, one row of bits for each row of pixels.

Definition 12.3 (Grey level)

The grey level of a pixel is a number from 0 to 255 that tells how light it is: 0 is black, 255 is white, and the numbers between are greys, darker for small numbers and lighter for large ones.

A grey level fits in one byte. For colours, a screen mixes light.

Definition 12.4 (RGB colour)

An RGB colour is a colour given by three numbers, each from 0 to 255: how much red, how much green and how much blue light to mix.

Mixing light. Each pixel of a screen is three tiny lights, red, green and blue; the three numbers of the pixel set how bright each one is.
Mixing light. Each pixel of a screen is three tiny lights, red, green and blue; the three numbers of the pixel set how bright each one is.

Mixing light is not like mixing paint: red and green light together look yellow, and all three at full strength look white. (255, 0, 0) is pure red, (0, 0, 0) is black, and (255, 255, 255) is white.

A drawing on a tablet: every stroke changes the three numbers of many pixels.
A drawing on a tablet: every stroke changes the three numbers of many pixels.

12.3 More pixels, more detail, a bigger file

Definition 12.5 (Resolution)

The resolution of a picture is its number of pixels, given as columns by rows: 8 by 8, or 19201920 by 10801080.

The same round shape at two resolutions. With more pixels, the edge is smoother; the picture also needs more numbers.
The same round shape at two resolutions. With more pixels, the edge is smoother; the picture also needs more numbers.

Example 12.6 (The size of a picture)

A small picture of 400 by 300 pixels has 400×300=120 000400 \times 300 = 120\,000 pixels. Kept as three bytes per pixel, one for each colour, it takes 120 000×3=360 000120\,000 \times 3 = 360\,000 bytes: 360 kilobytes. Twice as many columns and twice as many rows make four times as many pixels, and a file four times as big.

12.4 Sound as a long list of numbers

Sound is air that shakes back and forth very fast. A microphone turns the shaking into an electric signal, and the computer measures that signal many thousands of times every second: each measurement is a number. A song is a very long list of such numbers. To play it back, the computer sends the numbers to a speaker, in the same order and at the same speed, and the speaker shakes the air in the same way: we hear the sound again.

A sound as a wave (blue) and the measurements a computer keeps (red dots): one number at each tick of a clock.
A sound as a wave (blue) and the measurements a computer keeps (red dots): one number at each tick of a clock.

12.5 Everything in a file is bits

Text, pictures, sounds, films and programs are all kept in the same way: as numbers, and so as bits. The program that reads a file must know how the program that wrote it put the bits together. Many kinds of file begin with a few bytes that name their kind, and the extension of a file name (Chapter 7) tells the computer which program to try: one that knows how to turn these bits back into letters, colours or sounds.

12.6 Exercises

Exercise 12.1 ★

Write the word “CAT” as a list of character codes.

Solution

Solution of Exercise 12.1.

C is 67, A is 65, T is 84: 67, 65, 84.

Exercise 12.2 ★

Which word do the codes 79 and 75 make?

Solution

Solution of Exercise 12.2.

79 is O and 75 is K: “OK”.

Exercise 12.3 ★

Why do “A” and “a” have different codes?

Solution

Solution of Exercise 12.3.

They are different characters: the computer must know which one to show. A code table gives every character its own number.

Exercise 12.4 ★

Draw the picture of 5 by 5 pixels given by these rows of bits (1 for black): 00100, 01110, 11111, 01110, 00100.

Solution

Solution of Exercise 12.4.

A black diamond in a white square:

Exercise 12.5 ★

What is the grey level of a white pixel? Of a black one?

Solution

Solution of Exercise 12.5.

White: 255. Black: 0.

Exercise 12.6 ★

Give the three numbers of a pixel of pure red, then of pure blue.

Solution

Solution of Exercise 12.6.

Pure red: (255, 0, 0). Pure blue: (0, 0, 255).

Exercise 12.7 ★

A colour picture of 10 by 10 pixels is kept with three bytes per pixel. How many bytes does it take?

Solution

Solution of Exercise 12.7.

10×10=10010 \times 10 = 100 pixels, and 100×3=300100 \times 3 = 300 bytes.

Exercise 12.8 ★

Read the third row of bits of the smiley. What part of the face does it draw?

Solution

Solution of Exercise 12.8.

10100101: black pixels at the two edges (the outline of the face) and at the third and sixth places: the two eyes.

Exercise 12.9 ★★

Which colour does the pixel (255, 255, 0) show? And (0, 255, 255)?

Solution

Solution of Exercise 12.9.

(255, 255, 0) is full red and full green light, no blue: yellow. (0, 255, 255) is green and blue: cyan, a light blue-green.

Exercise 12.10 ★★

A picture of 100 by 100 pixels and a picture of 200 by 200 pixels are kept the same way. How many times bigger is the second file?

Solution

Solution of Exercise 12.10.

100×100=10 000100 \times 100 = 10\,000 pixels against 200×200=40 000200 \times 200 = 40\,000: the second file is 4 times bigger.

Exercise 12.11 ★★

The digit 7 is a character too. Its code is not 7: what is it? Why can the code of a digit not simply be the digit itself?

Solution

Solution of Exercise 12.11.

The code of the character 7 is 55 (0 is 48, 1 is 49, …). The small numbers of the table are already used for other things (the space is 32, and the numbers below it are control codes), and a text must be able to hold the character 7 without mixing it up with the number seven that a program counts with.

এই অধ্যায়ে সংজ্ঞায়িত পরিভাষা-শব্দ

পরিভাষায় সব 1050 টি শব্দ দেখো