Computer Fundamentals and Introduction to Programming · Lecture Notes
Chapter 1.1: Basic Concepts
Whatever a computer is used for, it works in the same simple way: it takes in data, processes it, presents the result, and stores it when necessary. Beneath this cycle lies an even simpler fact. Everything inside a computer, whether text, pictures, or music, is kept as a sequence of 0s and 1s. These notes first describe the working cycle and the hardware that takes part in each stage. They then turn to bits and bytes, the binary number system, and conversions between decimal and binary. Step-by-step calculations show how text, images, sound, and video become numbers, why files are compressed, and how memory sizes and network speeds are measured. Logical operations and the parity bit illustrate how a computer makes decisions with data and catches errors. The last two sections cover the kinds of computers and the place of information technology in everyday life.
Learning outcomes
- How a computer works
- Explain the input, processing, output, and storage stages; identify each stage, and the hardware involved, in a given task.
- Digital representation
- Interpret the role of bits, bytes, and the binary number system; convert among binary, decimal, and hexadecimal numbers; calculate the space taken by text, images, and sound.
- Data processing
- Show how arithmetic, comparison, and logical operations combine in decisions; explain the strength and the limits of error detection with a parity bit.
- Kinds of computers
- Compare computers by purpose and capacity; choose a suitable type for a given need and justify the choice.
- Information technology
- Explain how data becomes information and describe the data life cycle; discuss the role of information technology in everyday life and the responsibilities it brings.
1.1.1How a computer works
A calculator, a smartphone, a game console, and a bank’s large servers look nothing alike from the outside. Their sizes, prices, and jobs differ enormously. Yet all of them work in the same basic way. This section describes that shared design: what a computer is, which stages it passes a task through, and which hardware takes part in each stage.
1.1.1.1What is a computer?
In everyday speech, “computer” usually brings to mind a desktop case or a laptop. In computer science the concept is broader. The small control board inside a washing machine is a computer, and so are the racks that fill a server room. What they share is not that each is a single-purpose tool for one job, but that each processes data by following the instructions it is given.
A computer is an electronic system that processes the data it receives according to the instructions of a program. The raw values that enter the computer are called data; the interpretable result obtained after processing is called information. The sequence of instructions that tells the computer, step by step, what to do is called a program.
The three parts of the definition should be kept apart. Data is the material to be processed: an exam grade, a temperature reading, a letter typed on the keyboard. The program is the recipe that says what to do with the material: “add these two numbers,” “compute the average,” “write the result to the screen.” The computer is the machine that follows the recipe to the letter. Load a different program into the same machine and it does an entirely different job. This is what sets a computer apart from a calculator: what it does is not built into its hardware but determined by its program.
Figure 1.1.1 shows this model at the smallest scale. The numbers 12 and 8 mean nothing on their own; we do not know where they came from. The program tells the computer to add them, and the computer produces the result 20. “Sum: 20” is now a result that can be read and interpreted. The distinction between data and information is defined in detail in Definition 1.1.21.
The definition also contains the computer’s basic tasks. A computer takes in data from the user or from other systems. It processes that data according to the program and produces a meaningful result. It then presents the result to the user or stores it for later use. These four actions, receiving, processing, presenting, and storing, are the stages of the computer’s working cycle.
Believing that the computer “thinks” or “understands.” A computer carries out the instructions in a program very fast and without error, but it does not know what they are for. When it adds 12 and 8, it does not know whether they are exam grades, prices, or temperatures. It is the human who supplies the meaning and adds context to the data.
1.1.1.2The basic working cycle
A computer uses the same four stages in every task: input, processing, output, and storage. Because of the initial letters, this model is also called the IPOS model. While you type a text, watch a video, or play a game, these four stages repeat millions of times per second. The best way to get to know them is to follow them through one concrete task.
Input is taking data from the outside world into the computer. Processing is calculating, comparing, or transforming the data according to the program’s instructions. Output is presenting the processed result to the user or to another system. Storage is keeping the data and the results so that they can be used again later.
A student information system computes the semester average with the formula 0.4 × midterm + 0.6 × final. The teacher enters midterm = 70 and final = 90 for one student. The four stages run as follows:
- Input. The teacher types 70 and 90 into the boxes on the form. The keyboard sends every key press to the computer. At this stage the data is only carried into the computer; nothing has been calculated yet.
- Processing. The central processing unit (CPU) applies the formula. First two multiplications are done: 0.4 × 70 = 28 and 0.6 × 90 = 54. Then the two results are added: 28 + 54 = 82. These are arithmetic operations.
- Output. The result appears on the screen as “Average: 82.” The monitor is the output unit here.
- Storage. The student’s grade record is written to the database. So even if the computer is switched off, the record is not lost; when the transcript is prepared at the end of the term, the record is read and processed again.
Result: “Average: 82” appears on the screen, and the record is stored permanently.
Figure 1.1.2 shows how the four stages connect. Input, processing, and output form a one-way line: data enters on the left and leaves on the right as a result. Storage sits beside this line and talks to processing in both directions. Processing can write its result to storage, and if the same data is needed later, it can read it back. In the average example, the transcript calculation at the end of the term is done by reading the grades stored earlier. For that calculation, storage takes the place of input.
The four stages appear under the same names in every task, but they do not carry the same weight in every task. In a calculator, storage is almost absent; the result appears on the screen and is lost at the next calculation. In an archive system, storage is the main job. When applying the model to a task, first look for the answers to four questions: where does the data come from, what calculation is done on it, where does the result go, and what is stored?
When 500 TL is withdrawn from an ATM, the stages break down as follows:
- Input: the card reader reads the card’s data; the user enters the PIN and the amount of 500 TL on the keypad.
- Processing: the bank’s computer verifies the PIN, compares the balance with the amount to be withdrawn (is balance ≥ 500?), and computes the new balance (balance − 500).
- Output: the cash dispenser hands out the banknotes, the screen shows the new balance, and the printer prints the receipt.
- Storage: the transaction record and the new balance are written to the bank’s database.
The processing stage contains two kinds of work: a comparison (is the balance sufficient?) and an arithmetic operation (subtraction). Both are the processor’s job.
Mistaking a result shown on the screen for storage. The screen is output; what it displays disappears when the computer is switched off or the screen changes. For a result to count as stored, it must be written to a permanent medium, such as a disk or a database.
1.1.1.3Input
Input is the computer receiving data from the user, from a sensor, or from another system. The hardware that does this is called an input unit. The most familiar input units are the keyboard, the mouse, the microphone, and the touch screen. Sensors are input units too: a thermometer measures temperature, an accelerometer measures the tilt of a phone, and a camera measures light.
| Input unit | Physical event sensed | Data sent to the computer |
|---|---|---|
| Keyboard | A key is pressed | The key’s code (a character or a command) |
| Mouse | Movement and button presses | Change of position and clicks |
| Microphone | Fluctuations in air pressure (sound) | A sequence of numbers measured at regular intervals |
| Sensor | A quantity such as temperature, light, or acceleration | The measured value |
All the input units in the table do the same job: they turn a physical event into numbers, or more precisely into bits. There are no keys, sounds, or temperatures inside the computer, only numbers. An input unit’s task is to bring an event in the outside world into this form, which the computer can process.
Figure 1.1.3 shows this translation for one key press. When a key is pressed, the small controller inside the keyboard sends a code that says which key it was. The operating system translates this code into a character according to the selected keyboard layout. The character code of capital “A” is 65. The number 65 is held in memory as the eight-bit sequence 01000001. Why this sequence corresponds to 65 is worked out step by step in Example 1.1.4.
Counting the touch screen only as an output unit. A touch screen both displays an image (output) and senses the position of the touch (input). It is therefore both an input and an output unit.
1.1.1.4Processing
At the center of the processing stage is the central processing unit (CPU). In everyday speech it is simply called the processor. The processor executes program instructions one after another. Each instruction is a very simple task: add two numbers, read a number from memory, compare two numbers, jump to another instruction depending on the result. Complex programs consist of millions of such small instructions executed in succession.
The processor has three basic parts. The control unit fetches the next instruction, decodes what it asks for, and tells the other parts what to do; it manages the order of the instructions. The arithmetic logic unit (ALU) performs calculations such as addition and subtraction, and also comparisons. Registers are very small, very fast memory cells inside the processor; they temporarily hold the numbers being worked on.
Figure 1.1.4 shows the execution of a single addition instruction. The control unit decodes that the next instruction is ADD. The numbers to be added, 12 and 8, were loaded earlier into registers R1 and R2. The ALU reads these two registers, computes 12 + 8 = 20, and writes the result to register R3. The program’s next instruction is a comparison: is 20 greater than 15? The ALU answers this question too and produces 1, which means “true.”
The work the ALU does falls into two groups. Arithmetic operations calculate with numbers: addition, subtraction, multiplication, division. Logical operations compare values and combine conditions: “is 20 > 15?”, “are both the score sufficient and the attendance fine?” The result of a logical operation is always “true” or “false.” The computer’s “decision making,” that is, following different paths depending on a situation, is done with these operations. Both kinds of operation are shown in detail on a grade calculation in Figure 1.1.21.
In the processor, both the data and the instructions themselves are represented in binary form, that is, with 0s and 1s. The “ADD” instruction is also a bit sequence in memory; the control unit reads this sequence and understands which job is to be done. Because a program sits in memory just like data, making the computer do a new job takes nothing more than loading a new program into memory.
Measuring a processor’s speed only by asking “how many GHz?” The clock speed shows how many basic steps the processor takes per second. The number of steps an instruction takes, the number of cores, and how quickly data arrives from memory also determine speed. Two processors with the same clock speed can run the same program in different times.
1.1.1.5Output and storage
Output units turn processed information into a form that people can perceive or that another system can use. A monitor presents the result as an image, a printer on paper, and a speaker as sound. This is the reverse of what input units do: bits become light, ink, or sound again. The text “Average: 82” in the average example is the on-screen output of the calculation result.
Storage comes in two kinds, and this distinction matters a great deal in everyday computer use.
Volatile storage is memory that loses its contents when the power goes off. RAM (random access memory), the computer’s main memory, is volatile; it is very fast and holds the open programs and documents. Non-volatile storage is a medium that keeps data even without power: SSDs, hard disks (HDDs), USB flash drives, and memory cards are of this kind.
When a document is opened, a copy of it is read from non-volatile storage into RAM. Every change made to it is first applied to this copy in RAM. When the “Save” command is given, the current state in RAM is written to non-volatile storage, for example to the SSD. The reason for this order is speed. RAM is much faster than an SSD. If the processor went to the SSD for every letter, the computer would be very slow. The price of speed is safety: everything in RAM is erased when the power goes off.
Figure 1.1.5 shows these three moments in turn. In (a) the document lives only in RAM; if the power went off at that moment, all the work would be lost. In (b) “Save” writes a copy of the document to the SSD. In (c) the power goes off: everything in RAM is erased, but the two files written to the SSD stay where they are. When the computer is turned on again and the document is opened, the last saved state on the SSD is read back into RAM.
| Property | RAM (volatile) | SSD, hard disk (non-volatile) |
|---|---|---|
| When power goes off | Contents are erased | Contents are preserved |
| Speed | Very fast | Slow compared with RAM |
| Typical capacity | 8–32 GB | 256 GB – a few TB |
| What it holds | Running programs, open documents | Installed programs, saved files |
A student saves a homework document at 2:00 p.m. Between 2:00 and 2:20 she adds two pages to the document but does not save. At 2:20 the power goes off. What is seen when the computer is turned on again and the document is opened?
- The save at 2:00 wrote the document’s state at that moment to the SSD.
- The changes made between 2:00 and 2:20 were applied only to the copy in RAM.
- When the power goes off, the contents of RAM are erased; the two added pages are lost.
- When the document is opened again, the last save on the SSD, that is, the 2:00 state, is read into RAM.
Result: the document opens as it was at 2:00. Some programs have an “autorecovery” feature that writes a copy of the document to disk at regular intervals. If it is on, the loss of the last few minutes is reduced; but that is a separate save made by the program, and RAM itself preserves nothing.
Meaning the disk when saying “my computer’s memory is 512 GB.” 512 GB is usually the capacity of the SSD; RAM is much smaller (such as 8, 16, or 32 GB). Memory (RAM) and storage (SSD, disk) are separate pieces of hardware and do different jobs.
1.1.2Digital representation
The previous section said that input units turn every physical event into numbers. This section describes how those numbers are held inside the computer. The answer is surprisingly simple: a computer distinguishes only two states. These two states are called 0 and 1. All numbers, letters, and images are written as long sequences of these two symbols.
1.1.2.1All data becomes numbers
The data a computer handles is very varied: the letters in a message, the position of the mouse on the screen, the colors of a photograph, the sound of a song. The processor, however, works only with numbers. So for every kind of data there is a rule that turns it into numbers. The details of the rules differ from one kind of data to another, but the idea is always the same: split the data into parts and write each part as a number.
| Kind of data | Conversion rule | Example |
|---|---|---|
| Text | Each character has a code number. | A → 65 → 01000001 |
| Mouse movement | The position on the screen is written with two coordinates. | (x, y) → (420, 180) |
| Image | Each pixel is written with red, green, and blue components. | RGB(255, 0, 0): red |
| Sound | The sound wave is measured at regular intervals. | amplitude → sequence of numbers |
Figure 1.1.6 shows these four conversions side by side. The bottom row stresses an important consequence: after conversion, nothing in memory distinguishes a letter from a sound. All of it is bit sequences. Whether a bit sequence is a letter, a number, or a color is known to the program that reads it. This idea is taken up again in Figure 1.1.12.
1.1.2.2Bits, bytes, and place value
A bit, short for binary digit, is the smallest unit of information. A bit takes only one of two values: 0 or 1. A group of eight bits is called a byte: 1 byte = 8 bits.
In everyday life we write numbers in the decimal system. The decimal system has ten digits (0 to 9), and the value of each position is ten times the value of the position to its right. In the number 352, the 2 is in the ones position, the 5 in the tens position, and the 3 in the hundreds position:
352 = 3 × 100 + 5 × 10 + 2 × 1
The binary system applies the same idea with only two digits, 0 and 1. The value of each position is twice the value of the position to its right. The rightmost position has value 1; moving left, the values double: 2, 4, 8, 16, 32, 64, 128. These values are the powers of 2: 20 = 1, 21 = 2, 22 = 4, and so on. Positions are counted from the right starting at 0; the digit in position k has value 2k.
In a number system, each position has a place value. In the decimal system the place values are 1, 10, 100, …; in the binary system they are 1, 2, 4, 8, …. The value of a number is found by multiplying the digit in each position by that position’s value and adding the results. To avoid confusion about which system a number is written in, the base is written as a subscript: 1012 is a binary number, 10110 a decimal one.
101₂ and 101₁₀ are very different numbers. 101₁₀ is one hundred one. 101₂, on the other hand, is 1 × 4 + 0 × 2 + 1 × 1 = 5. When no base is written, the number is taken to be decimal; but in calculations where binary and decimal numbers appear together, stating the base prevents confusion.
Counting positions from the left. In a binary number the least significant position (the ones position) is always on the right, just like the ones position in the decimal system. The 1 in 1000₂ is in position 3 from the right, and its value is 23 = 8, not 1.
1.1.2.3Converting binary to decimal
To convert a binary number to decimal, write the place value under each bit and add the values of the bits that are 1. Bits that are 0 contribute nothing to the sum. Let us follow the method on the sequence 01000001, which is how the letter “A” on the keyboard appears in memory.
Let us convert 01000001₂ to decimal.
- Place values. Under the eight bits, write the values 1, 2, 4, 8, 16, 32, 64, 128 from right to left.
- Bits that are 1. The second bit from the left (position 6) is 1; its value is 64. The rightmost bit (position 0) is 1; its value is 1. The other six bits are 0.
- Sum. 64 + 1 = 65.
Result: 01000001₂ = 65₁₀. In the ASCII table, the number 65 corresponds to capital “A.”
| Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Bit | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 |
| Contribution | 0 | 64 | 0 | 0 | 0 | 0 | 0 | 1 |
Figure 1.1.7 is the visual counterpart of the calculation. Once the place values are memorized, converting binary to decimal comes down to adding a few numbers. The values of eight bits (128, 64, 32, 16, 8, 4, 2, 1) form a sequence that everyone who works in computer science ends up memorizing.
What is 11001010₂ in decimal?
- The bits from left to right are 1, 1, 0, 0, 1, 0, 1, 0; the place values are 128, 64, 32, 16, 8, 4, 2, 1.
- The values of the bits that are 1: 128, 64, 8, 2.
- Sum: 128 + 64 = 192; 192 + 8 = 200; 200 + 2 = 202.
Result: 11001010₂ = 202₁₀. A quick check: the rightmost bit is 0, so the number is even, and 202 is indeed even. If the rightmost bit were 1, the result would have to be odd.
Treating leading zeros as unimportant and shifting the place values. The leading 0 in 01000001 does not change the value of the number; 1000001₂ is also 65. But when the leading 0 is dropped, the number shrinks to seven bits and the leftmost 1 still has value 64, not 128. If place values are always assigned by counting from the right, this confusion does not arise.
1.1.2.4How many values do n bits represent?
A single bit represents two different values: 0 and 1. Two bits can form four different sequences: 00, 01, 10, 11. Three bits give eight sequences: 000 to 111. Each new bit is added by placing a 0 and then a 1 in front of every existing sequence, so the number of sequences doubles at every step.
Exactly 2n different bit sequences can be written with n bits. If these sequences are read as unsigned integers, they represent the numbers from 0 to 2n − 1.
The reason behind the theorem is a counting argument. Each bit has two choices, and the bits are chosen independently. The first bit has 2 choices and the second again 2, giving 2 × 2 = 4 sequences in all. For n bits the choices are multiplied n times: 2 × 2 × … × 2 = 2n. The smallest sequence is the one whose bits are all 0, and it represents 0. The largest is the one whose bits are all 1, and its value is 2n − 1. The reason is that 0 is counted too: the 2n values start at 0 and end at 2n − 1.
| Number of bits | Distinct values | Unsigned range |
|---|---|---|
| 1 bit | 21 = 2 | 0–1 |
| 2 bits | 22 = 4 | 0–3 |
| 8 bits | 28 = 256 | 0–255 |
| 10 bits | 210 = 1,024 | 0–1,023 |
| 16 bits | 216 = 65,536 | 0–65,535 |
| 32 bits | 232 = 4,294,967,296 | 0–4,294,967,295 |
Table 1.1.5 shows how fast this growth is. 8 bits give 256 values, which is why one byte holds a number between 0 and 255. 10 bits give 1,024 values, and this number comes up again later in the units of memory (1 KiB = 1,024 bytes). With 32 bits, more than four billion different values can be written. Adding one bit doubles the number of values; adding ten bits multiplies it by about a thousand, because 210 = 1,024.
Saying “8 bits count up to 256.” 8 bits represent 256 different values, but because these values start at 0, the largest is 255. Writing the number 256 takes 9 bits: 100000000₂.
1.1.2.5How many bits are needed?
The converse of the previous theorem is also asked often: if N different things are each to get a distinct code, what is the minimum number of bits needed? The answer is the smallest n that satisfies 2n ≥ N. This n is found by starting from 1 bit and adding bits until the number of codes reaches N. The algorithm in the slides expresses this idea in four lines:
N = 58 (29 uppercase + 29 lowercase letters)
n = 1; capacity = 2
while capacity < N: n = n + 1; capacity = capacity × 2
capacity ≥ N → n bits sufficeIn the algorithm, capacity holds the number of codes that can be written with n bits. At the start there is 1 bit and 2 codes. As long as the capacity stays below N, one bit is added and the capacity doubles. The moment the capacity reaches or passes N, the loop stops and the current n is the answer.
The Turkish alphabet has 29 letters. If uppercase and lowercase letters are coded separately, N = 58 different codes are needed. What is the minimum number of bits?
| n | capacity = 2n | capacity < 58? | Decision |
|---|---|---|---|
| 1 | 2 | yes | not enough, add a bit |
| 2 | 4 | yes | not enough, add a bit |
| 3 | 8 | yes | not enough, add a bit |
| 4 | 16 | yes | not enough, add a bit |
| 5 | 32 | yes | not enough, add a bit |
| 6 | 64 | no | enough, loop stops |
Result: 6 bits are needed. 58 of the 64 codes are used, so 64 − 58 = 6 codes are left unused. 5 bits are not enough, because 32 codes can cover only 32 of the 58 letters.
Figure 1.1.9 shows the same result with bars. Each bar is twice the previous one, and the first bar to pass the 58 line is the 6-bit one. A real text does not consist of letters alone: the ten digits, the space, and punctuation marks such as the period, comma, and question mark must also be coded. The ASCII (American Standard Code for Information Interchange) table, defined in the 1960s for English text, does this calculation with the English alphabet: 52 uppercase and lowercase letters, 10 digits, punctuation marks, and control characters exceed 64 codes, so ASCII is 7 bits wide (128 codes). The Turkish letters ç, ğ, ı, İ, ö, ş, ü are not in ASCII; for them, extended 8-bit encodings were used first, and today Unicode (UTF-8) is used.
The mathematical counterpart of this calculation is the logarithm: the number of bits needed is log2 N rounded up. Since log2 58 ≈ 5.86, 6 bits are needed. For someone who is not comfortable with logarithms, listing the powers of 2 in order gives the same result and is less error-prone.
Confusing the number of values to be coded with the largest value. If the numbers from 0 to 100 are to be coded, the number of values is 101, not 100. 26 = 64 is not enough, and since 27 = 128 ≥ 101, 7 bits are needed. The answer would also be 7 bits for the numbers from 0 to 127; for the numbers from 0 to 128, 8 bits would be needed.
1.1.2.6Converting decimal to binary
The most common method for the reverse conversion is the repeated-division method. The number is divided by 2 again and again, and the remainder of each division is noted. The remainder is always 0 or 1: 0 if the number is even, 1 if odd. The division ends when the quotient is 0. Reading the remainders from the last division to the first, that is, in reverse order, gives the binary number.
The method can be written as the following algorithm:
n ← N
bits ← ""
while n > 0 repeat:
r ← n mod 2
bits ← r + bits (r is added on the left)
n ← n div 2
print(bits)In the algorithm, mod gives the remainder of a division and div gives the integer quotient: 45 mod 2 = 1, 45 div 2 = 22. Each new remainder is added to the left of the bits accumulated so far. So the remainder of the first division ends up at the far right, and the remainder of the last division at the far left.
Let us convert 45 to binary.
| Step | Division | Quotient | Remainder | Accumulated bits |
|---|---|---|---|---|
| 1 | 45 ÷ 2 | 22 | 1 | 1 |
| 2 | 22 ÷ 2 | 11 | 0 | 01 |
| 3 | 11 ÷ 2 | 5 | 1 | 101 |
| 4 | 5 ÷ 2 | 2 | 1 | 1101 |
| 5 | 2 ÷ 2 | 1 | 0 | 01101 |
| 6 | 1 ÷ 2 | 0 | 1 | 101101 |
The division ends because the quotient is 0 at step 6. Result: 45₁₀ = 101101₂. To check, add the place values: the positions with a 1 in 101101₂ are 32, 8, 4, and 1; 32 + 8 + 4 + 1 = 45.
Why the method works can also be explained by a simple observation. The remainder of dividing a number by 2 is the rightmost bit of its binary form: the last bit of even numbers is 0, and of odd numbers it is 1. Dividing the number by 2 and discarding the remainder amounts to deleting the rightmost bit of the binary form. 45 = 101101₂. Dividing by 2 gives 22 = 10110₂; the last bit is gone. As the division continues, one more bit is read at each step, and the bits appear one by one from right to left.
Let us convert 156 to binary in two ways.
Method 1: repeated division. 156 ÷ 2 = 78, remainder 0. 78 ÷ 2 = 39, remainder 0. 39 ÷ 2 = 19, remainder 1. 19 ÷ 2 = 9, remainder 1. 9 ÷ 2 = 4, remainder 1. 4 ÷ 2 = 2, remainder 0. 2 ÷ 2 = 1, remainder 0. 1 ÷ 2 = 0, remainder 1. Reading the remainders from last to first gives 10011100₂.
Method 2: subtracting the largest place values. The largest power of 2 that fits into 156 is 128: 156 − 128 = 28. The largest power that fits into 28 is 16: 28 − 16 = 12. Then 8: 12 − 8 = 4. Then 4: 4 − 4 = 0. The values used are 128, 16, 8, and 4; write 1 in these positions and 0 in the others: 1001 1100₂.
Result: both methods give 156₁₀ = 10011100₂.
For someone who knows the place values well, the second method is usually faster. The first is a mechanical recipe that can be applied without thinking, and it is in a form a program can follow. The two methods always give the same result; one can serve as a check on the other.
Reading the remainders from the first division to the last. For 45 the remainders are 1, 0, 1, 1, 0, 1 in order, and written in that order they give 101101. This wrong reading happens to give the right result for 45, because the sequence is the same backwards. For 156 the remainders are 0, 0, 1, 1, 1, 0, 0, 1. Written in this order, 00111001₂ = 57, which is wrong. The correct reading is from last to first: 10011100₂ = 156. Going back at the end of every conversion and checking with place values catches this mistake at once.
1.1.2.7Hexadecimal notation
Long bit sequences are hard for people to read and write. In a 32-bit number it is very easy to write a single bit wrong. For this reason bit sequences are usually abbreviated in the hexadecimal system. Hexadecimal has 16 digits: 0–9, followed by the letters A, B, C, D, E, F for the values 10–15.
Hexadecimal is convenient because 16 = 24. Four bits represent exactly 16 different values, so each hexadecimal digit corresponds to exactly four bits. Converting a bit sequence to hexadecimal needs no arithmetic: the sequence is split into groups of four starting from the right, and each group is written as a single hexadecimal digit.
| Binary | Decimal | Hexadecimal | Binary | Decimal | Hexadecimal |
|---|---|---|---|---|---|
| 0000 | 0 | 0 | 1000 | 8 | 8 |
| 0001 | 1 | 1 | 1001 | 9 | 9 |
| 0010 | 2 | 2 | 1010 | 10 | A |
| 0011 | 3 | 3 | 1011 | 11 | B |
| 0100 | 4 | 4 | 1100 | 12 | C |
| 0101 | 5 | 5 | 1101 | 13 | D |
| 0110 | 6 | 6 | 1110 | 14 | E |
| 0111 | 7 | 7 | 1111 | 15 | F |
- 45 → hexadecimal. 45 = 101101₂. Pad it to eight bits: 0010 1101. 0010 = 2, 1101 = D. The result is 2D₁₆. Check: 2 × 16 + 13 = 45.
- 255 → hexadecimal. 255 = 1111 1111₂; both groups are 1111 = F. The result is FF₁₆. The largest value a byte can hold is written FF with two hexadecimal digits.
- A color code. Convert the components of the color with red = 59, green = 130, blue = 246 to hexadecimal. 59 = 0011 1011₂ = 3B₁₆. 130 = 1000 0010₂ = 82₁₆. 246 = 1111 0110₂ = F6₁₆. Written side by side, the components give the color code 3B82F6. Web pages write colors with these six-digit hexadecimal codes.
Hexadecimal notation is not a new kind of data; it is a shorter way of writing the same bit sequence. Memory addresses, color codes, and Unicode character numbers (for example U+0041 for “A”) are written in hexadecimal for this reason. By the same logic, groups of three bits can be written as a single digit; this is called octal notation: 101 101₂ = 55₈.
Splitting the bits into groups of four starting from the left. If 101101₂ is grouped from the left, it becomes 1011 01 and the result is wrong. Grouping is always done from the right; the incomplete group on the left is completed by adding zeros at the front: 10 1101 → 0010 1101 → 2D.
1.1.2.8Transistors
The answer to why computers use the binary system lies in the hardware. Processors and memories are built from very small electronic parts called transistors. A transistor works like a switch that controls the flow of electric current. What turns the switch on or off is not a mechanical lever but an electric voltage.
A transistor is a semiconductor device whose two terminals either pass current or do not, depending on the voltage applied to a third terminal (the gate). When enough voltage is applied to the gate, the transistor conducts and current flows; with no voltage it is in cutoff and no current flows. In computers these two states are interpreted as 1 and 0.
Figure 1.1.11 shows these two states with a lamp circuit. It also explains why a computer works in binary and not in decimal. It is easy to tell a switch’s two states, open and closed, apart reliably. Telling ten different voltage levels apart is much harder; a little electrical noise can turn a 6 into a 7. In a two-state system, even if the voltage drifts somewhat, the reading is not corrupted, because the gap between “high” and “low” is large.
A single transistor holds a single bit, or does a very simple job on a single bit. The power comes from the numbers. Logic gates are built by combining transistors, adders and memory cells by combining gates, and processors by combining those. A modern phone processor contains tens of billions of transistors. Each can switch on and off billions of times per second. The orderly cooperation of billions of simple switches makes complex jobs possible, such as playing a video or running an AI model.
Thinking of 0 as “nothing” or “no information.” 0 is as meaningful a value as 1: it reports that the transistor is in cutoff, that is, a particular state. The six zeros in 01000001 are needed for the number to be 65 at least as much as the two 1s.
1.1.3Representing data
Bits and bytes are the common alphabet in which a computer writes all its data. This section looks at how different kinds of data are written in this alphabet and how much space they take: numbers and text, images, sound, and video. It then describes two ways of making files smaller, lossless and lossy compression. The section ends with the units that measure the amount of data and with the difference between bits and bytes in speed and size.
1.1.3.1Numbers and text
Integers are stored directly as their binary equivalents. The number 13 sits in one byte as 00001101: 8 + 4 + 1 = 13. Negative numbers and numbers with fractional parts have separate binary encoding rules. For example, a number such as 3.75 is stored by splitting it into three parts: sign, exponent, and significant digits. This format is called a floating-point number. The details of these rules are beyond the scope of these notes. What should be remembered is that a rule agreed in advance exists for every kind of number.
Characters, that is, letters, digits, and signs, are converted to numbers by a code table. In the table, every character is given a number. When a computer stores a letter, it actually stores that letter’s number; when it writes to the screen, it draws the letter shape that corresponds to the number.
A character set is a table that pairs characters with numeric codes. ASCII is a 7-bit table of 128 characters that covers the English alphabet, digits, and punctuation marks. Unicode is the universal character standard that covers nearly all the world’s writing systems, mathematical symbols, and emoji, and defines more than a million code positions. The first 128 codes of Unicode are the same as ASCII.
The layout of the ASCII table makes some small calculations easy. Uppercase letters start at 65 (A) and are consecutive in alphabetical order: B = 66, C = 67, …, Z = 90. Lowercase letters start at 97 (a). The code of each lowercase letter is exactly 32 more than that of its uppercase form: a = 97 = 65 + 32. The digit characters start at 48: “0” = 48, “1” = 49, …, “9” = 57. There is an important distinction here. The code of the character “7” is 55; the number 7, however, is stored in binary as 00000111. A “7” typed on the keyboard must be converted before it is used as a number.
How many bytes does the word “Kedi” (Turkish for “cat”) take in ASCII, and with which bits is it stored in memory?
| Character | Code (decimal) | Bits | Calculation |
|---|---|---|---|
| K | 75 | 01001011 | 64 + 8 + 2 + 1 |
| e | 101 | 01100101 | 64 + 32 + 4 + 1 |
| d | 100 | 01100100 | 64 + 32 + 4 |
| i | 105 | 01101001 | 64 + 32 + 8 + 1 |
Result: four characters, one byte each, 4 bytes (32 bits) in total. The code of K is 10 more than that of A, because K comes 10 letters after A in the alphabet. The code of lowercase e is 32 more than that of uppercase E (69): 69 + 32 = 101.
ASCII covers only the English alphabet; Turkish letters such as “ğ,” “ş,” and “ı” are not in ASCII. Unicode solves this problem for all languages. In Unicode every character has a code point. A code point is written as a hexadecimal number starting with “U+”: “A” = U+0041 (decimal 65), “Ğ” = U+011E (decimal 286), “€” = U+20AC, the Chinese “中” = U+4E2D. How many bytes a code point takes in memory is decided by a separate encoding rule. The most common encoding on the web is UTF-8. UTF-8 writes ASCII characters with one byte, Turkish letters with two bytes, and characters such as “€” and “中” with three bytes.
| Character | Code point | Decimal | UTF-8 bytes (hexadecimal) | Number of bytes |
|---|---|---|---|---|
| A | U+0041 | 65 | 41 | 1 |
| Ğ | U+011E | 286 | C4 9E | 2 |
| € | U+20AC | 8,364 | E2 82 AC | 3 |
| 中 | U+4E2D | 20,013 | E4 B8 AD | 3 |
This distinction has a practical consequence. “Kedi” is also 4 bytes in UTF-8. “Kağıt” (Turkish for “paper”), however, is 7 bytes even though it has five characters: “K,” “a,” and “t” take one byte each, “ğ” and “ı” two bytes each. The number of characters and the number of bytes differ when non-ASCII letters are used.
The most important consequence of the idea of encoding is this: the meaning of a bit sequence is determined not by the sequence itself but by the rule used when reading it.
Figure 1.1.12 shows this on a single byte. The bits 01000001 in memory are the number 65 to a calculator program, the letter “A” to a text editor, and perhaps a dark gray shade of one pixel to an image program. This is why, when a file is opened with the wrong encoding, meaningless marks such as “ı” or “ÅŸ” appear in place of Turkish letters: the bytes are correct, but they were read with the wrong rule.
Saying “a character is always one byte.” This is true only for ASCII. In UTF-8 a character takes between 1 and 4 bytes; Turkish text therefore takes slightly more bytes than it has characters.
1.1.3.2Images
A photograph seen on a screen consists, up close, of small colored squares. Each square is called a pixel (short for “picture element”). A pixel is the smallest part of the image painted a single color. An image is stored as a table of pixels: a certain number of pixels in each row, and one color in each pixel.
The resolution of an image is its number of horizontal and vertical pixels, written “width × height,” such as 1920 × 1080. In the RGB color model, the color of each pixel is defined by a mixture of three components: red, green, and blue. Each component is a number between 0 and 255 and takes one byte.
The RGB model is based on how a screen produces light. Each pixel on the screen is really three small light sources side by side: one red, one green, one blue. The value of a component sets the brightness of that light. 0 means the light is completely off, 255 means fully bright. When all three lights are fully bright, the eye sees white: RGB(255, 255, 255). If all three are off, black is seen: RGB(0, 0, 0). If only red is fully bright, the color is pure red: RGB(255, 0, 0). When red and green are lit together, yellow is obtained: RGB(255, 255, 0). If the three components are equal, the color is a shade of gray; the larger the value, the lighter the gray.
Figure 1.1.13 shows this arrangement on a very small image. The image has 8 columns and 6 rows, 48 pixels in all. In the selected blue pixel the blue component has the largest value (246) and the red the smallest (59). Each component is one byte, that is, eight bits. Since a pixel is three bytes, the whole image takes 48 × 3 = 144 bytes. In a real photograph the calculation is the same; only the number of pixels runs into the millions.
Comparing RGB to mixing paint. As paints are mixed, the color gets darker; mixing red, green, and blue paint gives a dark brownish color. On a screen, light is mixed, and as light is added the color gets lighter; the full mixture of the three lights is white.
1.1.3.3Color depth and image size
The number of bits used to write the color of a pixel is called the color depth or bit depth. Bit depth determines the number of different colors that can be shown. By Theorem 1.1.1, a pixel of b bits can take 2b different colors.
| Bits / pixel | Distinct colors | Typical use |
|---|---|---|
| 1 | 21 = 2 | Black-and-white drawings, fax, document scanning |
| 8 | 28 = 256 | Grayscale or 256-color palette images (GIF) |
| 24 | 224 = 16,777,216 | Photographs: 8 bits each for R, G, and B |
| 32 | 16.7 million colors + transparency | Interface graphics, PNG (alpha channel) |
24 bits give more colors than the human eye can distinguish; this is the standard depth for photographs. At 32 bits the color is still 24 bits; the remaining 8 bits hold transparency information called the alpha channel. If alpha is 0 the pixel is fully transparent, and if it is 255 it is fully opaque. It is thanks to this channel that the corners of an app icon show the background color.
Bit depth and resolution together determine the size of an uncompressed image:
size (bytes) = width × height × bit depth ÷ 8
The ÷ 8 in the formula converts the total in bits to bytes. If the number of bytes per pixel is an integer (such as 24 bits = 3 bytes), the calculation gets even shorter: size = number of pixels × bytes per pixel.
Let us compute the uncompressed size of an 800 × 600 image for three different bit depths. (Decimal units are 1 KB = 1,000 bytes and 1 MB = 1,000,000 bytes; the binary units in parentheses are 1 KiB = 1,024 bytes and 1 MiB = 1,048,576 bytes.)
- Number of pixels: 800 × 600 = 480,000 pixels.
- 24 bits (3 bytes/pixel): 480,000 × 3 = 1,440,000 bytes ≈ 1.44 MB (divided by 1,048,576 it is ≈ 1.37 MiB).
- 8 bits (1 byte/pixel): 480,000 × 1 = 480,000 bytes = 480 KB (480,000 ÷ 1,024 ≈ 468.75 KiB).
- 1 bit: 480,000 ÷ 8 = 60,000 bytes = 60 KB (60,000 ÷ 1,024 ≈ 58.6 KiB).
Result: the same image takes ≈ 1.44 MB (1.37 MiB) at 24 bits, 480 KB (468.75 KiB) at 8 bits, and 60 KB (58.6 KiB) at 1 bit. The 24-bit version is exactly 24 times the 1-bit version, because the number of pixels is the same and only the number of bits per pixel has changed.
As color depth increases, color transitions get smoother, but the file gets bigger. In an 8-bit palette image only 256 colors are available, so regions where tones change slowly, such as the sky, show visible steps. At 24 bits the same transition looks continuous to the eye. The effect of resolution is even greater: if width and height are each doubled, the number of pixels, and so the size, quadruples.
Treating bit depth as bytes and forgetting to divide by 8. One gets 800 × 600 × 24 = 11,520,000, and if one says “11.5 million bytes,” the result is eight times too large. 11,520,000 is in bits; to convert to bytes, divide by 8: 1,440,000 bytes.
1.1.3.4Sound and video
Sound is fluctuation of pressure in the air. A microphone turns this fluctuation into an electric voltage that varies continuously with time. A computer cannot store a continuous wave as it is; it has infinitely many points. Instead, the wave is measured at equal intervals. This process is called sampling, and each measurement is a sample. Each measurement is also rounded to the nearest of a set of levels and turned into an integer.
In the upper part of Figure 1.1.14, the wave is measured at 12 equally spaced points. Samples near the crest of the wave take the value 7, and samples near the trough take 0. The computer stores not the wave itself but these 12 numbers. When the sound is played back, the numbers are turned into a voltage one by one, and the speaker vibrates with that voltage.
Video consists of still images shown one after another. Each image is called a frame. When frames are shown fast enough, the eye cannot see them separately and perceives motion. The number of frames shown per second is called fps (frames per second). Cinema traditionally uses 24 fps, television and internet videos mostly 30 fps; in games 60 fps and above is common. The sound of a video is stored in a separate channel from the picture frames and is played in sync with the frames during playback.
If a video at 1920 × 1080 resolution, 24-bit color, and 30 fps were stored uncompressed, how much space would one minute take? (Sound is ignored; 1 GiB = 230 = 1,073,741,824 bytes.)
- One frame: 1920 × 1080 = 2,073,600 pixels; × 3 bytes = 6,220,800 bytes.
- One second: 30 frames × 6,220,800 = 186,624,000 bytes, about 187 MB per second (178 MiB).
- One minute: 60 seconds × 186,624,000 = 11,197,440,000 bytes.
- Converting to GiB: 11,197,440,000 ÷ 1,073,741,824 ≈ 10.43 GiB.
Result: one minute of uncompressed Full HD video takes about 10.4 GiB. An ordinary video file with about 100 MB per minute is a hundred times smaller; the difference comes from compression.
1.1.3.5Digitizing sound
An analog sound signal becomes digital data in three steps: sampling, quantization, and encoding. The algorithm in the slides lists these steps and the size formula as follows:
analog signal: continuous wave
sample: measure at equal intervals
quantize: round to the nearest level (3 bits → 0…7)
encode: write each level with 3 bits
size = sampling rate × bit depth × channels × duration
lossy compression (MP3)Sampling is measuring the signal at equal time intervals; the number of measurements per second is called the sampling rate and is measured in hertz (Hz). Quantization is rounding each measurement to the nearest of a predetermined finite set of levels; the difference between the measurement and the level is called the quantization error. Encoding is writing the number of each level as a binary number. The number of bits used to write one sample is called the bit depth.
Let us follow the steps on the small example in the slides. The signal is measured eight times at equal intervals. The measurements have fractional parts: 4.76, 6.55, 6.55, 4.76, 2.24, 0.45, 0.45, 2.24. How the signal changes between two measurements is not recorded; sampling inevitably loses this information.
Let us use 3 bits for quantization. By Theorem 1.1.1, 3 bits give 23 = 8 levels: 0, 1, …, 7. Each measurement is rounded to the nearest integer (Figure 1.1.15, bottom).
| Example | Measurement | Level | Quantization error | 3-bit code |
|---|---|---|---|---|
| 1 | 4.76 | 5 | 0.24 | 101 |
| 2 | 6.55 | 7 | 0.45 | 111 |
| 3 | 6.55 | 7 | 0.45 | 111 |
| 4 | 4.76 | 5 | 0.24 | 101 |
| 5 | 2.24 | 2 | 0.24 | 010 |
| 6 | 0.45 | 0 | 0.45 | 000 |
| 7 | 0.45 | 0 | 0.45 | 000 |
| 8 | 2.24 | 2 | 0.24 | 010 |
Table 1.1.9 gives the results of all three steps together. The quantization error is at most 0.45 of a level. When rounding to the nearest level, the error can never exceed half a level, because every measurement lies between two levels and is at most 0.5 from the nearer one. In the encoding step, each level is written as a 3-bit binary number: 5 → 101, 7 → 111, 2 → 010, 0 → 000. Eight samples take 8 × 3 = 24 bits.
This small example grows in two ways for real sound. The first is the sampling rate. Eight measurements per second are not enough to make human speech intelligible; real recordings take thousands of samples per second, and CD quality takes 44,100. The second is the bit depth. Eight levels from 3 bits are like a coarse staircase; a CD uses 16 bits and has 216 = 65,536 levels. On a staircase this fine, the quantization error shrinks below what the ear can hear.
size (bits) = sampling rate × bit depth × number of channels × duration (s)
How many bytes does one minute of CD-quality sound (44,100 Hz, 16 bits, 2 channels: left and right) take? How much space does the same music take if recorded as 128 kbit/s MP3?
- Bits per second: 44,100 × 16 × 2 = 1,411,200 bit/s.
- One minute: 1,411,200 × 60 = 84,672,000 bits.
- Converting to bytes: 84,672,000 ÷ 8 = 10,584,000 bytes ≈ 10.6 MB (≈ 10.1 MiB if 1 MiB = 1,048,576 bytes is used).
- MP3: 128 kbit/s = 128,000 bit/s. In one minute, 128,000 × 60 = 7,680,000 bits, that is, 7,680,000 ÷ 8 = 960,000 bytes ≈ 0.96 MB (0.92 MiB).
- Ratio: 10,584,000 ÷ 960,000 ≈ 11.
Result: one minute of CD quality ≈ 10.6 MB (10.1 MiB), while the same minute as a 128 kbit/s MP3 ≈ 0.96 MB; the MP3 is about 11 times smaller.
MP3 achieves this reduction with lossy compression: it discards details the ear barely notices, for example very quiet sounds that come right after a loud one. A discarded detail never comes back.
Forgetting the number of channels. In a stereo (two-channel) recording, separate samples are stored for the left and right speakers; the size is twice that of a mono recording. If the factor 2 is left out of the CD calculation, the result is ≈ 5 MB, which is wrong.
1.1.3.6Lossless and lossy compression
Uncompressed images, sound, and video take a lot of space. For this reason files are usually stored compressed. Compression is a way of writing the same data with fewer bits. It comes in two basic kinds, and the difference between them is whether the decompressed file is identical to the original.
Lossless compression gives back the original data exactly, bit for bit, when decompressed; it works by shortening repetitions in the data. Lossy compression permanently discards details that the human eye and ear barely notice; when decompressed, it gives a copy that is close to the original but different from it.
| Lossless | Lossy | |
|---|---|---|
| On decompression | The original data comes back exactly, bit for bit | A copy close to the original is obtained |
| Method | Shortens repetitions (RLE, ZIP) | Discards detail the eye and ear barely notice |
| Example formats | ZIP, PNG, FLAC | JPEG, MP3, MP4 (H.264) |
| Typical reduction | Usually 2–3 times | 10 times or more |
| Suitable data | Text, programs, spreadsheets, medical images | Photos, music, video |
The nature of the data determines which kind to choose. If even a single bit of a program changes, the program fails or runs wrongly. In a text file, changing a single bit turns one letter into another. In a bank table, 1,000 TL turning into 1,008 TL is unacceptable. This data is compressed only losslessly. In medical images, too, a small detail can matter for diagnosis, so lossless formats are preferred. In photos, music, and video, small changes in the color of a few pixels or in a very quiet sound go unnoticed. This data is compressed lossily and made ten times smaller or more.
Lossy compression has a hidden cost. When a lossy file is opened, edited, and saved again, the compression is applied again, and each time a little more detail is discarded. Editing and saving the same JPEG photo many times produces growing blur and blocky distortions in the image. A discarded detail does not come back. For this reason, original files being worked on are kept in a lossless format, and the lossy version is produced only for sharing.
Thinking that saving a JPEG file as PNG will bring back the lost quality. PNG is lossless, but it preserves only the data it is given. The detail discarded by JPEG compression is nowhere any more; PNG can only store the degraded version without further degradation.
1.1.3.7Run-length encoding (RLE)
The simplest example of lossless compression is run-length encoding (RLE). The idea is this: if the same value repeats many times in a row, instead of writing the value over and over, write “how many times it repeats” and “the value itself.” A block of identical consecutive values is called a run. For example, the sequence “AAAAABBB” is written (5, A)(3, B).
RLE is a lossless compression method that reads a sequence from left to right and writes each run as a (length, value) pair. During reading, a counter and the current value are kept. If the incoming item equals the current value, the counter goes up by one. If it differs, the run that has ended is written to the output as (counter, current value), the counter returns to 1, and the new value becomes the current value. When the sequence ends, the last run, still open, is written too.
A 16-pixel row of an image consists of two colors: B (blue) and W (white). With pixel numbers from 0 to 15, the row is BBBBBBWWWWBBBWWW. Each pixel takes one byte; the row is 16 bytes.
| Pixel | Color | Event | Counter | Output |
|---|---|---|---|---|
| 0 | B | first pixel, current color B | 1 | — |
| 1–5 | B | same color, the counter goes up at each pixel | 6 | — |
| 6 | W | color changed, the run ends | 1 | (6, B) |
| 7–9 | W | same color | 4 | (6, B) |
| 10 | B | color changed | 1 | (6, B) (4, W) |
| 11–12 | B | same color | 3 | (6, B) (4, W) |
| 13 | W | color changed | 1 | (6, B) (4, W) (3, B) |
| 14–15 | W | same color | 3 | (6, B) (4, W) (3, B) |
| (last) | — | row ended, the open run is written | — | (6, B) (4, W) (3, B) (3, W) |
Result: four pairs are obtained. Each pair is 2 bytes (one byte for the length, one for the color): 4 × 2 = 8 bytes. The original row was 16 bytes; RLE has halved it. To check, add the lengths: 6 + 4 + 3 + 3 = 16 pixels.
Decoding is the reverse of encoding. Each pair is read and the value is written as many times as the length: (6, B) → BBBBBB, (4, W) → WWWW, (3, B) → BBB, (3, W) → WWW. The row obtained is identical to the original row; no information has been lost. This is why RLE is lossless.
The lower part of Figure 1.1.17 shows the limit of the method. If the color changes at every pixel, no run is longer than one. A (1, color) pair is written for each of the 16 pixels: 16 × 2 = 32 bytes. The “compressed” data has doubled in size. RLE works only on data with plenty of long repetitions: black-and-white scanned documents, flat-color drawings, icons. In photographs, neighboring pixels are rarely exactly the same color; so other methods are used for photographs.
Forgetting to write the run at the end of the sequence. RLE writes a run only when the color changes. After the last run the color does not change; the sequence just ends. If this last step is skipped, the output in the example stops at (6, B) (4, W) (3, B), and the last three white pixels are lost; the decoded row is 13 pixels.
1.1.3.8Units of memory
In the earlier calculations, byte counts reached millions and billions. To write such large numbers comfortably, larger units are used. The units form a ladder that starts at the bit and grows at every step.
| Decimal (SI) | In bytes | Binary (IEC) | In bytes |
|---|---|---|---|
| bit (binary digit) | 0 or 1 | ||
| byte (B) | 8 bits | ||
| KB (kilobyte) | 103 = 1,000 | KiB (kibibyte) | 210 = 1,024 |
| MB (megabyte) | 106 = 1,000,000 | MiB (mebibyte) | 220 = 1,048,576 |
| GB (gigabyte) | 109 = 1,000,000,000 | GiB (gibibyte) | 230 = 1,073,741,824 |
| TB (terabyte) | 1012 | TiB (tebibyte) | 240 ≈ 1.1 × 1012 |
| PB (petabyte) | 1015 | PiB (pebibyte) | 250 ≈ 1.13 × 1015 |
The first two rows of the table are different: a byte is 8 times a bit. After the byte there are two scales. In decimal (SI) units, each step is 1,000 times the previous one; “kilo” means thousand. In binary (IEC) units, each step is 1,024 times the previous one. The number 1,024 was not chosen at random; it is 210 and very close to 1,000. Because memories work with binary addresses, their capacities are naturally powers of 2. For this reason “KB” was used for many years to mean 1,024 bytes as well, and this usage is still common today.
Familiar examples help in getting a feel for the size of the units. A single character is 1 byte. Half a page of plain text takes a few KB. A phone photo is about 3 MB, and an HD movie about 4 GB. Laptop disks are usually between 512 GB and 1 TB. The data centers of a large cloud service store petabytes of data.
With binary units (1 KiB = 1,024 B, 1 MiB = 1,024 KiB, 1 GiB = 1,024 MiB):
- How many bits is 3 KiB? 3 × 1,024 = 3,072 bytes; 3,072 × 8 = 24,576 bits.
- How many 4 MiB photos fit into a 128 GiB memory? 128 × 1,024 = 131,072 MiB; 131,072 ÷ 4 = 32,768 photos. (The space taken by the operating system and applications is ignored in this calculation.)
- How many MiB is 5,000,000 bytes? 5,000,000 ÷ 1,048,576 ≈ 4.77 MiB. In decimal units the same number is exactly 5 MB.
Going from a larger unit to a smaller one you multiply; going from a smaller one to a larger one you divide. The factor between byte and bit is 8; at every other step it is 1,024 for binary units and 1,000 for decimal units.
The small difference between 1,024 and 1,000 grows at larger units and causes confusion. To separate the two meanings, the International Electrotechnical Commission (IEC) gave the binary units the separate names in Table 1.1.11. 1,024 bytes is a KiB (kibibyte), 220 bytes a MiB (mebibyte), and 230 bytes a GiB (gibibyte). In this definition the prefixes KB, MB, GB keep their decimal meanings: 1 GB = 109 = 1,000,000,000 bytes. Disk manufacturers write capacity with this decimal (SI) definition. Operating systems often compute size in binary units but still display it as “GB.”
Why does a disk labeled “1 TB” on the box appear as about 931 GB in the operating system?
- The manufacturer uses the decimal definition: 1 TB = 1012 = 1,000,000,000,000 bytes.
- The operating system divides the byte count by 1 GiB = 230 = 1,073,741,824 bytes: 1,000,000,000,000 ÷ 1,073,741,824 ≈ 931.3.
- The screen says “931 GB”; its correct name is “931 GiB.”
Result: there are no missing bytes on the disk. The byte count is the same in both counts; only the definition of the unit differs. The difference grows as the unit gets larger: 2.4% at KB, 7.4% at GB, about 10% at TB.
Thinking the difference between 1 TB and 931 GB is “space lost in formatting” or “bad sectors.” The space taken by formatting and the file system is very small. Almost all of the difference comes from the definition of the unit; the two numbers write the same amount of bytes in different units.
1.1.3.9Bits or bytes? Speed and size
In unit abbreviations, uppercase and lowercase are not the same thing. A lowercase b stands for bit, an uppercase B for byte. Between 100 Mb (megabits) and 100 MB (megabytes) there is exactly a factor of 8. This distinction matters most when internet speed and file size are discussed together, because the two are traditionally measured in different units.
Data transfer rate is measured in bits per second: bit/s, kbit/s, Mbit/s (Mbps for short). The prefixes in speed units are decimal: 1 Mbps = 106 = 1,000,000 bit/s. File and disk size, on the other hand, is measured in bytes: KB, MB, GB.
When calculating how long a file takes to download, the two units must be converted into the same language. Either the speed is converted to bytes (divided by 8) or the size is converted to bits (multiplied by 8). Both ways give the same result.
With a connection of 100 Mbps, in how many seconds does a 3 GB file (3 × 109 bytes) download in the best case?
| Step | Calculation | Result |
|---|---|---|
| Speed converted to bytes | 100,000,000 ÷ 8 | 12,500,000 bytes/s = 12.5 MB/s |
| File converted to bits | 3 × 109 bytes × 8 | 24 × 109 bits |
| Time | 24 × 109 ÷ 108 | 240 s = 4 minutes |
The same result comes from the first row: 3,000,000,000 ÷ 12,500,000 = 240 s. If one thought “at 100 Mbps, 100 MB downloads per second,” the time would come out as 30 seconds, which is an eighth of reality.
240 seconds is the best case. In reality the time is longer. Every piece of data sent over a network has addressing and control information added; this protocol overhead uses part of the line. Other devices sharing the same line divide the speed. The server itself can send data only at a limited rate. So on a 100 Mbps connection, download speeds of around 10–11 MB/s are usually seen.
Comparing the “11 MB/s” shown by the download program with the “100 Mbps” in the internet plan and concluding that the speed is low. 11 MB/s = 88 Mbps; given the overhead and sharing, this is a good value for a 100 Mbps line.
1.1.4Data processing
A computer does not merely store data; it calculates with it and makes decisions. This section covers the basic kinds of operations the processor performs. It then shows, with the parity bit as an example, how the same operations are used to tell whether data has been corrupted in transmission.
1.1.4.1Arithmetic and logical operations
Most of what programs do is a combination of four kinds of operations.
| Kind | What it does | Operators | Type of result |
|---|---|---|---|
| Arithmetic | Calculates with numbers | + − × ÷ % | Number |
| Comparison | Tests the relationship between two values | > < ≥ ≤ == != | True / false |
| Logical | Combines conditions or reverses them | AND, OR, NOT | True / false |
| Decision | Chooses the path the program follows depending on the result | if … then | One path |
Of the arithmetic operators, the % sign means not percent but the remainder of a division: 17 % 5 = 2, because there are three 5s in 17 and 2 is left over. This is the same operation as the “mod” used in decimal-to-binary conversion. Among the comparison operators, == means “is equal?” and != means “is not equal?” Because a single = sign is used for assignment in programming languages, the question of equality is written with two equal signs.
The inputs and outputs of logical operations are true or false. In a computer, true is represented by 1 and false by 0. There are three basic logical operations.
AND gives true if both conditions are true, and false if at least one is false. OR gives true if at least one of the conditions is true, and false if both are false. NOT reverses a single condition; it makes true false and false true.
| A | B | A AND B | A OR B | NOT A |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 |
Table 1.1.13 covers every case in four rows, because two conditions can take only four combinations of values. In the AND column only the last row is 1: AND requires both sides to hold. In the OR column only the first row is 0: OR is satisfied if just one side holds. The everyday “and” and “or” are used in these senses too. “A student who passed the exam and has full attendance” requires both conditions. “A passenger who has an ID or a passport” finds either one sufficient.
In a course the rule is as follows: average = (midterm + final) / 2; a student whose average is 60 or above and who meets the attendance requirement passes. Let us follow two students.
| Step | Student 1 | Student 2 |
|---|---|---|
| Data | midterm 60, final 80, attendance_ok = true | midterm 40, final 90, attendance_ok = false |
| Arithmetic | (60 + 80) / 2 = 70 | (40 + 90) / 2 = 65 |
| Comparison | 70 ≥ 60 → 1 | 65 ≥ 60 → 1 |
| Logical | 1 AND 1 → 1 | 1 AND 0 → 0 |
| Decision | “passed” | “failed” |
The second student’s average is sufficient, but because the attendance condition is not met, the AND operation gives 0. If the rule had been written with “or” (1 OR 0 = 1), this student would have passed too. The choice of connective changes the meaning of the rule.
Figure 1.1.21 and Example 1.1.18 show how the four kinds of operations work as a chain. The arithmetic operation produces the number. The comparison turns this number into a true/false value. The logical operation combines several true/false values. The decision step then chooses the path according to the final value. The first three jobs are done in the ALU. In the decision step, the control unit selects the program’s next instruction according to the result.
Confusing “greater than” with “greater than or equal to.” If a score of 60 is to count as passing, the condition must be “score ≥ 60,” not “score > 60.” If “score > 60” is written, a student who gets exactly 60 fails. Which side of the condition the boundary values fall on should always be checked separately.
1.1.4.2Error detection with a parity bit
When data passes through a cable or a wireless link, electrical noise can corrupt some bits. A bit that is 1 can flip to 0, or a bit that is 0 to 1. How will the receiver know whether the bits that reached it are correct? The simplest solution is to add one extra bit to the data for checking purposes.
A parity bit is a check bit added to the data bits that makes the total number of 1s follow a predetermined rule. Under the even parity rule, the parity bit is chosen so that the total number of 1s in the data bits and the parity bit is even. If the number of 1s in the data bits is even, the parity bit is 0; if odd, it is 1. The receiver counts the 1s in all the bits; if the count is odd, there is an error.
A counterpart of this rule is odd parity: there the total number of 1s must be odd. The two rules are equally strong; it is enough that the sender and the receiver use the same one. The example below uses even parity.
In ASCII the code of the letter “Y” is 89; in seven bits it is written 1011001. This letter is sent with even parity.
- The sender counts the 1s. In 1011001 the 1s are in bits 1, 3, 4, and 7: four of them. Because four is even, the parity bit is 0. The eight bits sent: 10110010.
- One bit is corrupted in transmission. Noise flips bit 3 from 1 to 0. The receiver gets 10010010.
- The receiver counts the 1s. In 10010010 there are three 1s. Three is an odd number; the even-parity rule is violated. The receiver notices the error and asks for the data again.
Result: the single-bit error is caught. But the receiver knows only that an error exists; it cannot tell which bit was corrupted. So it cannot correct the error itself and asks for the data to be sent again.
The last row of Figure 1.1.22 shows the limit of the parity bit. If bits 3 and 4 are corrupted together, the receiver gets 10000010. This sequence has two 1s; two is an even number. The receiver sees that the rule holds and takes the corrupted data for correct. The general rule is this: corrupting one bit raises or lowers the number of 1s by one, that is, it changes the odd/even state. Corrupting two bits changes the state twice and returns it to the start. For this reason a parity bit catches only an odd number of bit errors; an even number of errors goes unnoticed.
| Corrupted bits | Received sequence | Number of 1s | Receiver’s decision | Actual situation |
|---|---|---|---|---|
| None | 10110010 | 4 (even) | No error | Correct |
| bit 3 | 10010010 | 3 (odd) | Error | Caught |
| Bits 3 and 4 | 10000010 | 2 (even) | No error | Missed |
| Bits 1, 3, and 4 | 00000010 | 1 (odd) | Error | Caught |
The parity bit is a very cheap check: a single extra bit for every seven or eight bits. It works in settings where errors are rare and come one at a time. In settings where noise corrupts bits in bursts, stronger methods are used. These methods add more check bits to catch multiple errors, and some can even locate the error and correct it. The error-correcting codes (ECC) used in memory modules and the checksums in internet packets are of this kind.
Using the value of the data bits (89) or the number of bits (7) when computing the parity bit. Parity looks only at the number of bits that are 1. 89, the value of 1011001, is odd, but the number of 1s in it is four, which is even; the parity bit is 0.
1.1.5Kinds of computers
All computers use the same working cycle, but they are built in different forms for different jobs. A machine that runs a weather model and the control board of a washing machine are two very different computers working on the same principles. This section describes the main kinds of computers, the need each one meets, and where they differ from one another.
1.1.5.1Classification by capacity and purpose
Computers are most often classified by two criteria: capacity (how much computing power, memory, and storage they offer) and purpose (whom they serve and for what job). Table 1.1.15 summarizes the main kinds by these two criteria.
| Kind | Primary purpose | Typical example |
|---|---|---|
| Supercomputer | Intensive scientific computation | Climate model, physics simulation |
| Mainframe | A very large number of reliable transactions | Banking, insurance |
| Server | Service over a network | Website, e-mail, database |
| Personal computer | Individual use | Desktop, laptop |
| Embedded system | A specific function of a device | Air conditioner, car, washing machine |
| Thin client | Access to a central system | Library or bank branch terminal |
| Mobile device | Portable use | Phone, tablet |
| Quantum computer | Special classes of problems | Chemistry simulation, research |
This classification has no sharp boundaries. A powerful desktop computer acts as a server once a website is set up on it. A smartphone is both a mobile device and a personal computer. A car contains dozens of embedded computers, and they talk to one another over a network. Which kind a device falls into depends less on its hardware than on how it is being used at the moment.
1.1.5.2Supercomputers and mainframes
At the top of the capacity scale there are two kinds. Both are very powerful and expensive, but each is designed to do a different thing best.
A supercomputer is a computer that solves a single large problem requiring very high computing power by splitting it across thousands of processors and working on the parts in parallel. A mainframe is a computer designed to run small transactions from a large number of users simultaneously, without interruption, and reliably.
Figure 1.1.23 shows the difference between the two kinds through their workloads. When a supercomputer is given a climate model, the Earth’s atmosphere is divided into millions of small cells. Each processor computes the temperature, pressure, and wind of a few cells and shares its results with its neighbors. A job that would take months on a single computer finishes in a few hours. Supercomputers are also used in physics simulations, in drug and materials research, and in training large AI models. Their power is measured by the number of floating-point operations per second (FLOPS).
The mainframe’s job is different. A bank receives thousands of card payments, transfers, and balance queries every second. Each of these transactions is tiny on its own; the hard part is to process all of them at once, without a single error, and without ever stopping. An hour’s outage of a payment system causes large losses. Mainframes are therefore built with redundant hardware: when a part fails, the system keeps running without stopping, and the part can be replaced while it runs.
| Priority | Supercomputer | Mainframe |
|---|---|---|
| Main goal | Computing speed | Transaction volume and continuity |
| Typical workload | Large scientific computation | A large number of enterprise transactions |
| Users | A small number of researchers | Thousands of simultaneous users |
| Measure of success | Operations per second (FLOPS) | Transactions per second, uptime |
Taking a mainframe for an “old, slow supercomputer.” The two kinds are not different points on the same scale; they are designed for different purposes. A supercomputer is not suitable for a bank’s work, nor a mainframe for a climate model.
1.1.5.3Servers and thin clients
A server is a computer that provides web, e-mail, file, database, or application services to other computers over a network. The computer that receives the service is called a client. A thin client is a simple client that leaves most of the processing to the server and does only display and input on its own hardware.
The conversation between a server and a client follows a request–response pattern. The client asks for something; the server processes the request and sends the result back. This pattern works both when a web page is opened and when an e-mail is downloaded.
A grade list is opened from a thin client in a university library. Figure 1.1.24 shows three steps:
- Request. Client 1 sends the “grade list” request to the server over the network. All the client does is turn the click on the screen into a request.
- Processing. The real work is done on the server: the database is queried, the grades are found, the averages are computed, and the result is prepared as a screen.
- Response. The ready screen returns to the client. The thin client only displays it and waits for the user’s next click.
The working cycle is split between two computers here: input and output are on the client, processing and storage on the server.
The advantage of the thin client is ease of management. In a library with a hundred thin clients, programs are installed only on the server and updated only there. Because no data is kept on the clients, no data is lost when one breaks or is stolen; a new one is plugged in. The local hardware can be cheap and simple. The weakness is dependence: if the network or the server goes down, all hundred clients become useless at once.
Thinking of a server only as a big, special machine. “Server” is a role more than a type of hardware. A laptop at home is a server for the other computers while a file-sharing program runs on it. Servers in data centers, on the other hand, are built to take on this role continuously: powerful, redundant, and shaped to fit in racks.
1.1.5.4Personal and mobile devices
A personal computer is a general-purpose computer designed for use by a single person. Personal and mobile devices are forms of the same general-purpose computer adapted to different conditions of use.
| Device | Distinguishing feature | Trade-off |
|---|---|---|
| Desktop | Fixed use, expandable hardware, high performance | Not portable, uses more power |
| Laptop | Portable build, battery | Hardware upgrades are limited |
| Tablet | Touch screen, light use | Hard to write long texts or do heavy work |
| Phone | Mobile connectivity, sensors (GPS, accelerometer, camera), apps | Small screen, limited battery |
On a desktop computer the case can be opened; the graphics card, memory, or disk can be replaced and upgraded. Thanks to plenty of power and ample cooling space, it gives the highest performance for the same price. A laptop fits the same parts into a small body and battery; part of the performance is sacrificed for portability and battery life. Tablets and phones go further in this direction: power consumption is kept so low that the processor runs without a cooling fan.
What really sets the phone apart from other personal devices is its sensors. The location receiver, accelerometer, gyroscope, camera, microphone, and fingerprint reader turn the phone into an input device that constantly measures the world. A map app showing direction, the screen rotating when the phone is turned sideways, and the step counter working are all thanks to these sensors.
Performance is not the only criterion in choosing a device. Portability, power consumption, screen size, and the main purpose of use are considered together. For a student who will write long reports and do programming, a laptop with a good keyboard and a large screen is more suitable than the fastest phone.
1.1.5.5Embedded computers
An embedded system is a computer placed inside a larger device that carries out a specific task of that device. It is usually built around a microcontroller, which combines the processor, memory, and input–output units on a single chip.
Embedded computers are the most numerous kind of computer. A car has dozens of embedded computers that control the engine, the brakes, and the airbags. A washing machine, a microwave oven, an air conditioner, a smartwatch, a medical measuring device, and a traffic light each contain an embedded computer. The common features of these computers are as follows:
- They do a single job, and their programs are loaded when the device is manufactured.
- They consume little power and work with limited memory and limited computing power.
- Reliability and real-time response matter: an airbag controller must detect a collision and decide within milliseconds.
- The user usually does not notice that there is a computer inside the device.
An embedded computer repeats its working cycle continuously as a control loop: measure, decide, act, measure again. In the air-conditioner example, the input unit is a temperature sensor, and the output unit is an actuator that switches the compressor on and off.
The air conditioner’s target temperature is 24 °C and the rule is: if the measured temperature is greater than the target, the compressor switches on; otherwise it switches off. The sensor measures 28, 26, and 24 °C in succession.
| Round | Measurement (input) | Condition (processing) | Compressor (output) | Room |
|---|---|---|---|---|
| 1 | 28 °C | 28 > 24 → true | ON | cools |
| 2 | 26 °C | 26 > 24 → true | ON | cools |
| 3 | 24 °C | 24 > 24 → false | OFF | cooling stops |
In the third round 24 is not greater than 24; it is equal to it. The “greater than” condition is false, and the compressor switches off. The loop does not end here. The sensor keeps measuring; when the room warms up and the temperature rises above 24 again, the compressor switches on again.
This simple rule has a flaw in practice. If the temperature drifts back and forth between 24.0 and 24.1, the compressor switches on and off too often and wears out. Real air conditioners therefore use two thresholds: for example, it switches on when the temperature passes 25 and off when it falls below 23. In the region in between, the compressor keeps its previous state. This small change shows that in embedded systems the software directly affects the life of the hardware.
Thinking that an embedded computer’s loop runs once and ends. A calculator program gives its result and stops; an embedded control program keeps measuring and deciding without ever stopping for as long as the device is on.
1.1.5.6Quantum computers
All the computers described so far process information with bits that are 0 or 1. Quantum computers use a different unit of information, based on the rules of quantum physics.
A qubit (quantum bit) is a unit of information that, before it is measured, can exist in a combination of the states 0 and 1. When a qubit is measured it gives 0 or 1; which one comes out is determined with a probability that depends on the weights in the combination. A quantum computer is a computer that calculates with qubits.
For certain classes of problems, quantum computers offer computing methods very different from classical computers. Simulating the behavior of molecules and materials, certain optimization problems, and breaking some encryption methods are studied among these classes. The problem of factoring large numbers into primes in particular is watched closely, because it is the problem on whose difficulty the security of some widely used encryption systems rests today.
That said, quantum computers have not replaced classical computers in everyday use, and they are not expected to replace them in general-purpose use in the near future. Qubits are disturbed by the slightest influence from the environment; for this reason most quantum computers are operated cooled to temperatures close to absolute zero. For tasks such as word processing, browsing the internet, or calculating a spreadsheet, a quantum computer has no advantage at all. A quantum computer is not a faster version of a classical computer but a different tool designed for particular problems.
Thinking that a qubit “tries all the answers at the same time and picks the right one.” A measurement always gives a single result. Quantum algorithms are carefully designed to lower the probability of wrong answers and raise the probability of the right one; this is possible only for certain problems.
1.1.6Information technology
The previous sections looked inside the computer: at bits, operations, and kinds of hardware. This section looks outward, at the systems that computers form together with people and organizations. The whole of these systems, which turn data into information, is called information technology.
1.1.6.1What is information technology?
Information technology (IT) is the whole of the systems used to collect, process, store, and transmit data. An IT system has four technical components: hardware (physical devices), software (programs and operating systems), data (the raw values being processed), and communication (networks and data transfer).
Figure 1.1.27 stresses that an IT system does not consist of computers alone. Consider the patient record system of a hospital. The hardware is the servers, computers, and printers. The software is the record program and the database. The data is patient information, test results, and prescriptions. Communication is the network between buildings. But the system does not work without the secretaries who enter the records, the doctors who read them, and the rules that decide who may see which information. The people, processes, and security rules in the outer ring of the system are as important as the technical components. Even the best hardware is not secure if a user writes the password on paper and sticks it to the screen.
1.1.6.2The difference between data and information
In everyday language, data and information are mostly used with the same meaning. In computer science there is a clear difference between them, and this difference explains the reason for the existence of every IT system.
Data is a raw measurement, number, text, or record; without context its meaning may remain unclear. Information is a meaningful result, useful for making decisions, that emerges when data is organized, processed, and interpreted in a context.
A piece of paper has only these three numbers on it: 38, 41, 39. How do these numbers become information?
- Raw data. 38, 41, 39 are only numbers. They have no meaning unless it is known what was measured: they could be ages, exam scores, or speeds.
- Context. It is added that they are three temperature readings of a patient during the day, and the unit is °C. Now what the numbers show is clear.
- Processing. The average is computed: (38 + 41 + 39) / 3 = 118 / 3 ≈ 39.3.
- Information. “The patient’s average temperature is 39.3 °C; the fever is high.” A decision can be based on this sentence: the patient is given a fever reducer.
Figure 1.1.28 gathers the steps of the conversion on a single line. The computer does only the processing part of these steps: it adds and divides. It is the human who knows that the numbers are temperature readings and that 39.3 °C should count as “high.” Without the human who adds the context and interprets the result, the computer’s output is still only a number. If the same 39.3 had been a room temperature, the interpretation would be entirely different.
Thinking that the more data is collected, the more information is obtained. Data whose context is unclear, disorganized, or erroneous gives no information however much of it there is; it can even lead to wrong interpretations. Information comes not from the amount of data but from organizing and interpreting it correctly.
1.1.6.3Information technology in everyday life
Information technology is part of everyday tasks today in almost every field. A few examples show how the same working cycle looks in different fields.
- Education: online courses, digital course materials, and learning platforms. A student information system collects grades (input), computes averages (processing), shows the transcript (output), and keeps the records for years (storage).
- Health: electronic patient records, imaging systems (X-ray, MRI), and patient monitoring. A patient’s test results can be accessed in the same record from different hospitals.
- Finance: banking, payment systems, and transaction security. A card payment is approved within seconds by passing through computers in several countries.
- Business and entertainment: corporate communication, automation of business processes, games, and media services. A music app recommends new songs based on the songs a listener has played.
IT contributes in a similar way in all of these fields: collecting data faster, processing it more accurately, keeping it longer, and delivering it sooner to the person who needs it.
1.1.6.4The data life cycle
Data does not wander at random in an IT system; it passes through certain stages. The whole of these stages is called the data life cycle.
The data life cycle has four stages. Collection: data is taken from people, machines, or sensors. Processing: erroneous data is filtered out and calculations are made. Storage: data is kept in a file, a database, or the cloud. Presentation: the result is shared as a report, table, chart, or application screen. Decisions made on the basis of the presented result start the collection of new data, and the cycle turns again.
The sensor of a weather station sends four temperature readings: 21.4 · −99 · 22.1 · 23 (°C). When the sensor cannot take a measurement, it sends −99 as a “fault” code.
- Collection. The four values are received from the sensor.
- Processing. −99 is not a real temperature but a fault code; it is discarded. The average of the remaining three readings is taken: (21.4 + 22.1 + 23) / 3 = 66.5 / 3 ≈ 22.17, that is, about 22.2 °C.
- Storage. The readings and the average are saved to the database together with the time.
- Presentation. A daily temperature chart is published on a web page. A farmer who follows the chart sets the irrigation time accordingly; this decision is tested as new readings are collected.
If −99 had not been discarded, the average would have been (21.4 − 99 + 22.1 + 23) / 4 = −32.5 / 4 ≈ −8.1 °C. This number means nothing in midsummer. Filtering at the processing stage is essential for data to become information.
Figure 1.1.29 shows that the cycle is a closed ring. The data life cycle closely resembles the computer’s input–processing–output–storage cycle, but its scale is different. The computer’s cycle turns on a single machine within a thousandth of a second. The data life cycle spreads across all of an organization’s systems and can take days, months, even years.
Writing zero instead of “ignoring” the faulty data. If −99 is counted as 0 instead of being discarded, the average comes out as (21.4 + 0 + 22.1 + 23) / 4 ≈ 16.6 °C, which is still wrong. A missing or faulty reading must not enter the average at all; the divisor is also the number of valid readings, not the number of readings.
1.1.6.5Benefits and responsibilities
Information technology brings important conveniences:
- Speed and automation: data is processed millions of times faster than it could be by hand; repetitive tasks, such as computing the averages of all students, are done automatically.
- Access and communication: it becomes easier to reach and share information from different places; a doctor can see the test results of a patient in another city.
The same conveniences also create new responsibilities:
- Privacy and security: personal data must be protected against unauthorized access and loss. A leak of a health record or bank details harms the person for a long time. In Türkiye, the processing of personal data is regulated by Law No. 6698 on the Protection of Personal Data (KVKK).
- Accuracy and ethics: wrong data and biased systems can produce faulty results. Software that learns from biased decisions in the past can repeat the same bias quickly and at large scale.
Security is therefore not only a technical matter. Even the strongest encryption gives no protection if a user types their password into a fake e-mail. The security of an IT system depends on hardware and software, but also on the knowledge of the people who use it, on the organization’s rules, and on how well those rules are applied. Technological convenience does not remove the obligation to use data correctly, securely, and responsibly.
1.1.6.6The future of information technology
Today, four areas visibly drive the development of information technology.
| Area | Short definition |
|---|---|
| Artificial intelligence | Decision-support and generative systems that learn patterns from data |
| Internet of Things | Devices with sensors sharing data over a network |
| Cloud computing | Providing computing and storage resources over a network |
| Big data analytics | Drawing meaningful results from high-volume and varied data |
These four areas often work together in a single system. Figure 1.1.30 illustrates this with a smart irrigation system.
The sensor in the field is part of the Internet of Things: it measures soil moisture and sends it over the network. The measurements are stored in the cloud, that is, not on the farmer’s own computer but on servers rented over the network. Big data analytics compares the moisture, weather, and crop data of thousands of fields in the same region. Artificial intelligence, based on what it has learned from this comparison, makes the “irrigate now” decision, and the valve opens. After irrigation, new measurements arrive and the cycle starts again. In essence this system, too, is a large-scale application of the data life cycle and of the computer’s basic working cycle.
New technologies bring new questions with them. The energy consumed by data centers keeps rising. People without access to technology can be left behind as services go digital. Connecting more devices to the network widens the attack surface. Who is to answer for the decisions made by artificial intelligence is still debated. The future of information technology will be shaped not only by technical progress but also by the answers given to questions of energy, accessibility, security, and ethics.
1.1.7Summary
- A computer is an electronic system that processes the data it receives according to program instructions. In every task it uses the same four stages: input, processing, output, and storage. Storage talks to processing in both directions: results are written and read back when needed.
- Input units turn physical events into bits. In the processor, the control unit manages the order of instructions, the ALU does calculations and comparisons, and the registers hold the values being worked on.
- RAM is fast but volatile; its contents are erased when the power goes off. SSDs and hard disks are non-volatile. “Save” copies the document from RAM to non-volatile storage.
- In a computer, all kinds of data are represented by sequences of bits; 8 bits make 1 byte. The meaning of a bit sequence is determined by the rule (the encoding) used to read it.
- n bits represent 2n different values (unsigned 0 … 2n − 1). For N values you need the smallest n with 2n ≥ N: 6 bits for 58 letters.
- To convert binary to decimal, add the place values of the bits that are 1. To convert decimal to binary, divide the number by 2 repeatedly and read the remainders from last to first: 45 = 101101₂. Each hexadecimal digit corresponds to four bits: 45 = 2D₁₆.
- A transistor is a two-state switch; conducting is read as 1, cutoff as 0. Because telling two states apart is reliable, computers work in binary.
- Text is stored with ASCII or Unicode codes, and images with pixels that have RGB components. The size of an uncompressed image is width × height × bit depth ÷ 8 bytes.
- Sound becomes numbers through sampling, quantization, and encoding; size = sampling rate × bit depth × channels × duration. One minute of CD quality is ≈ 10.6 MB (10.1 MiB). Video consists of frames shown at a certain number per second (fps).
- Compression can be lossless (ZIP, PNG; the original data comes back exactly) or lossy (JPEG, MP3; detail is discarded). RLE writes consecutive repetitions as (length, value) pairs; it shrinks data with long repetitions and enlarges data that changes often.
- Beyond the byte, decimal (SI) units grow by factors of 1,000 (KB, MB, GB) and binary (IEC) units by factors of 1,024 (KiB, MiB, GiB). Disk makers use SI, while operating systems often show the binary value labeled “GB”; this is why 1 TB appears as ≈ 931 GiB. Network speed is measured in bits per second and file size in bytes; 100 Mbps = 12.5 MB/s.
- AND requires both conditions, OR at least one; NOT reverses a condition. Arithmetic, comparison, logical operations, and the decision work as a chain.
- A parity bit catches an odd number of bit errors but cannot locate them; an even number of errors goes unnoticed.
- Kinds of computers are told apart by purpose, capacity, and environment: a supercomputer is designed for speed, a mainframe for continuity, a server for network service, and an embedded system for the task of a single device. A quantum computer is a different tool for particular problems.
- Information technology consists of hardware, software, data, and communication together with people, processes, and security rules. The computer processes data; it is the human who adds context and turns it into information. Data passes through a life cycle of collection, processing, storage, and presentation.
| Question | Rule | Example |
|---|---|---|
| How many values do n bits give? | 2n | 8 bits → 256 |
| How many bits for N values? | Smallest n with 2n ≥ N | 58 → 6 bits |
| Binary to decimal | Sum of the place values of the bits that are 1 | 01000001₂ = 64 + 1 = 65 |
| Decimal to binary | Repeated division by 2; remainders read from last to first | 45 = 101101₂ |
| Binary to hexadecimal | Group in fours from the right | 0010 1101₂ = 2D₁₆ |
| Image size | width × height × bit depth ÷ 8 | 800 × 600, 24 bits → 1,440,000 bytes |
| Sound size | sampling rate × bit depth × channels × duration ÷ 8 | CD, 1 min → 10,584,000 bytes |
| Download time | size (bits) ÷ speed (bit/s) | 3 GB, 100 Mbps → 240 s |
1.1.8Key terms
- computer
- data
- information
- input unit
- output unit
- storage
- central processing unit (CPU)
- control unit
- arithmetic logic unit (ALU)
- register
- random access memory (RAM)
- volatile / non-volatile
- bit
- byte
- binary
- decimal
- hexadecimal
- digit / place value
- transistor
- character set
- ASCII
- Unicode
- encoding
- pixel
- resolution
- color depth
- sampling / sample
- sampling rate
- quantization
- frame
- lossless compression
- lossy compression
- run-length encoding (RLE)
- kilobyte / megabyte / gigabyte / terabyte
- kibibyte / mebibyte / gibibyte
- arithmetic operation
- comparison
- logical operation
- parity bit
- supercomputer
- mainframe
- server
- client
- thin client
- request / response
- personal computer
- mobile device
- embedded system
- microcontroller
- sensor
- quantum computer
- qubit (quantum bit)
- information technology (IT)
- data life cycle
- privacy
- artificial intelligence
- Internet of Things
- cloud computing
- big data
1.1.9Test Yourself
What is 10110110₂ in decimal? What is its hexadecimal form?
Answer
The place values of the bits that are 1 are 128, 32, 16, 4, and 2: 128 + 32 + 16 + 4 + 2 = 182. The groups of four are 1011 = B and 0110 = 6; the hexadecimal form is B6₁₆. Check: 11 × 16 + 6 = 182.
Which sequence results when 100 is converted to binary by repeated division by 2? How is the result checked with place values?
Answer
100 ÷ 2 = 50 remainder 0; 50 ÷ 2 = 25 remainder 0; 25 ÷ 2 = 12 remainder 1; 12 ÷ 2 = 6 remainder 0; 6 ÷ 2 = 3 remainder 0; 3 ÷ 2 = 1 remainder 1; 1 ÷ 2 = 0 remainder 1. The remainders read from last to first give 1100100₂. Check: 64 + 32 + 4 = 100.
A faculty has 100 laboratory lockers numbered 0 to 99. What is the minimum number of bits needed to encode each locker’s number in binary? How many codes are left unused?
Answer
The number of values to be coded is 100. Since 26 = 64 < 100, 6 bits are not enough; since 27 = 128 ≥ 100, 7 bits are needed. 128 − 100 = 28 codes are left unused.
How many bytes does an uncompressed 640 × 480 image with 24-bit color take? How many KB and KiB is that? What is the size if the same image is converted to 8-bit grayscale?
Answer
The number of pixels is 640 × 480 = 307,200. Since 24 bits = 3 bytes, 307,200 × 3 = 921,600 bytes ≈ 922 KB; 921,600 ÷ 1,024 = 900 KiB. At 8 bits, 1 byte per pixel remains: 307,200 bytes = 300 KiB (≈ 307 KB), that is, one third.
How many bytes does a 30-second mono (single-channel) audio recording take, made with a 44,100 Hz sampling rate and 16-bit depth?
Answer
44,100 × 16 × 1 × 30 = 21,168,000 bits; ÷ 8 = 2,646,000 bytes ≈ 2.65 MB (≈ 2.52 MiB if 1 MiB = 1,048,576 bytes is used). If the recording were stereo, the size would double to 5,292,000 bytes.
How is the row WWWBBBBBBBWW (W = white, B = blue; each pixel 1 byte) encoded with RLE? How many bytes are saved?
Answer
The runs are three white, seven blue, and two white: (3, W) (7, B) (2, W). Three pairs × 2 bytes = 6 bytes; the original row is 12 bytes. 6 bytes are saved and the row is halved. The sum of the lengths is 3 + 7 + 2 = 12.
Seven data bits 1101000 are sent with even parity. What is the parity bit? If 11000001 reaches the receiver, what does the receiver decide?
Answer
1101000 has three 1s; to make the total even the parity bit is 1, and the sequence sent is 11010001. The received 11000001 has three 1s; the count is odd, so the receiver knows there is an error and asks for the data again. (In reality bit 4 flipped from 1 to 0; the receiver cannot tell where.)
With a 50 Mbps connection, in how many seconds does a 1.5 GB (1.5 × 109 bytes) file download in the best case?
Answer
The file is converted to bits: 1.5 × 109 × 8 = 12 × 109 bits. The speed is 50 × 106 bit/s. The time is 12 × 109 ÷ (50 × 106) = 240 s = 4 minutes. It can also be found by converting the speed to bytes: 50 Mbps = 6.25 MB/s; 1,500 MB ÷ 6.25 = 240 s.
About how many GiB does a disk labeled “500 GB” on the box show in the operating system?
Answer
The manufacturer uses decimal units: 500 × 109 bytes. The operating system divides this by 230 = 1,073,741,824 bytes: ≈ 465.7 GiB. No bytes are lost; the difference comes from the definition of the unit.
A greenhouse’s ventilation turns on with the condition (temperature > 28) AND (humidity < 60). When the temperature is 30 °C and the humidity is 70%, what is the value of the condition? What would happen if OR were written instead of AND?
Answer
30 > 28 is true (1); 70 < 60 is false (0). 1 AND 0 = 0: the ventilation does not turn on. With OR, 1 OR 0 = 1 and the ventilation turns on. With the same data, the choice of connective changes the decision.
1.1.10Further reading
- J. G. Brookshear and D. Brylow, Computer Science: An Overview (13th ed., Pearson, 2019), Chapter 1: the storage of bits, the binary system, the representation of text, images, and sound, data compression, and transmission errors are covered in an order very close to these notes and with plenty of examples.
- W. Stallings, Computer Organization and Architecture (11th ed., Pearson, 2019), Chapters 1–2: the basic structure of a computer, the parts of the processor, and the historical development of computers are covered from a more detailed hardware viewpoint.
- C. Petzold, Code: The Hidden Language of Computer Hardware and Software (2nd ed., Microsoft Press, 2022): starting from Morse code and light bulbs, it builds up binary numbers, logic gates, and the processor without requiring technical background.
1.1.11References
- J. G. Brookshear, D. Brylow, Computer Science: An Overview, Pearson.
- W. Stallings, Computer Organization and Architecture, Pearson.
- The Unicode Consortium, The Unicode Standard.
- NIST, Glossary of Key Information Security Terms (NISTIR 7298).
- IEC 80000-13, Quantities and units — Part 13: Information science and technology (binary prefixes: kibi, mebi, gibi).
- Law No. 6698 on the Protection of Personal Data, Official Gazette, 7 April 2016.
Related pages: Chapter 1.1 slides · Study questions · Number Base Converter · Glossary · © Sercan Külcü. All rights reserved.