How Computer Works

How Does the Computer Work?

Let us first discuss some of the fundamentals before learning a programming language to get awareness about a few things. Mostly in academics, these are the basic concepts that are taught. So, let us first understand what a computer is, how a computer works, and what number systems are.

What is a Computer?

A computer is a machine, or you can say it is an electronic device that performs operations or calculations based on instructions provided by the user (through software or hardware programs). It will accept data (input from the user), process it as per the instructions provided by the user, and then produce outputs. Computers can also store data for later use in storage devices and retrieve it whenever necessary.

A computer can perform a wide range of tasks, from simple calculations to complex operations involving data manipulation, storage, and retrieval. Computers are made up of hardware and software components:

  • Hardware refers to the physical components of a computer, such as the central processing unit (CPU), memory (RAM), storage devices (like hard drives or SSDs), and input/output devices (such as keyboards, mice, and monitors).
  • Software includes operating systems (like Windows, macOS, Linux) and applications (Web Browsers, Office suites, and Games) instructing the hardware on what tasks to perform.

Computers vary in size and capability, from small devices like smartphones and tablets to large systems like servers or supercomputers. They play essential roles in various fields, including education, science, industry, entertainment, and personal use, due to their ability to process vast amounts of information quickly and accurately.

How Does the Computer Work?

Let us discuss how the computer works. To understand how a computer works, please look at the following basic block diagram of a computer and let us try to understand the different components of a computer.

How does the computer work?

Let’s study the components of a computer. The computer consists of the following components.

  • CPU- Central Processing Unit.
  • Main Memory
  • Hard disk
  • Input devices
  • Output devices

Let us understand the components in detail.

CPU – Central Processing Unit

CPU is the heart of the computer. CPU stands for Central Processing Unit or Microprocessor. The computer’s brain is the CPU, where actual data manipulation or Operations happen using ALU (Arithmetic and Logical Unit). Programs, which are sets of instructions stored in memory, are executed by the CPU step by step. The CPU consists of two components, i.e., ALU (Arithmetic Logic Unit) and CU (Control Unit).

  • ALU- Arithmetic Logic Unit: The ALU performs arithmetic and logical operations on the provided data. Arithmetic operations include basic computations such as addition, subtraction, multiplication, and division, while logical operations include operations such as AND, OR, NOT, XOR (exclusive OR), comparisons like greater than, less than, equal to, etc. The ALU takes in the data from the input registers, processes it as per the instruction, and then outputs the result, which may either be stored back in a register or used in further computations.
  • CU- Control Unit: On the other hand, the Control Unit is responsible for directing the processor’s operations. It acts as the brain within the CPU, fetching instructions from memory, decoding them to understand the required action, and then executing them by coordinating with the appropriate components of the system, including the ALU, memory, and input/output devices. The CU controls the flow of data within the CPU and between the CPU and other components of the computer system, ensuring that the instructions are executed in the correct sequence and at the right time.

The ALU and CU enable the CPU to perform a wide range of functions, from simple calculations and data processing to complex decision-making and control operations. 

Hard Disk:

A hard disk is a storage device for a computer. It is the long-term memory where data is stored persistently, even when the computer is turned off. It’s slower than RAM but can hold much more data. It is a non-volatile storage device that retains the data even when the computer is turned off. Hard disks are used to store the operating system, software applications, and most other files.

It contains two types of files, i.e., data files and program files. Data files and program files are two fundamental types of files stored on a hard disk in a computer. Each serves distinct purposes and plays a crucial role in the functioning of a computer system. Here’s a closer look at both:

Data Files

Data files are created by users or generated by software applications to store information. This information can vary widely, from documents created in word processors to databases managed by database management software, images, videos, spreadsheets, etc. The key characteristic of data files is that they do not contain code that is executed directly by the computer’s CPU. Instead, they are read by software applications that perform operations based on the data contained within these files. Examples of data files include:

  • Text documents (.txt, .docx, .pdf)
  • Spreadsheets (.xls, .xlsx)
  • Presentations (.ppt, .pptx)
  • Databases (.db, .sql)
  • Images (.jpg, .png, .gif)
  • Audio files (.mp3, .wav)
  • Video files (.mp4, .avi)
Program Files

On the other hand, Program Files contain executable code that tells a computer what operations to perform. When you run a program, the computer’s CPU reads and executes the code contained within these files. Program files can include applications, system services, libraries, and other components necessary to operate complex software systems. Examples of program files include:

  • Executable files (.exe on Windows, no extension or .app on macOS, .bin or no extension on Linux)
  • Dynamic link libraries (.dll on Windows)
  • Shared libraries (.so on Linux, .dylib on macOS)
  • Scripts (.sh for shell scripts, .py for Python scripts)
  • System files necessary for operating system operation, which could be in various formats depending on the OS

If you take the example of the notepad on our computer, it is a program file. So, when we open Notepad, it’s a program and a file is available, i.e., a Program file (notepad.exe). So, basically, we click on the notepad icon, and the program will start, but if you look into My Computer and folders, somewhere you will find the program file for the notepad (C:\Windows\System32), and the file name will be notepad.exe. Now, if you type something in Notepad and save it, it will save as a text file such as MyDoc.txt, and it is a data file used by Notepad or generated by Notepad. For a better understanding, please have a look at the below diagram.

how does computer memory work

  • Program files: The music player on the computer, notepad on the computer, and MS Office on the computer are program files. That means any application or software installed on the computer is a program file.
  • Data files: Movies, Songs, Word Documents, Text Documents, etc. are data files. The data files contain the actual data. We need a program file if you want to perform read and write operations on the data (i.e., the data file).

Note: Without a program file, we cannot perform the read and write operations on the data file. For example, you have a .doc file, but if you have uninstalled MS Office from your machine, then even though you have the doc file, you cannot perform any operation on that doc file.

Main Memory:

Main memory, also known as RAM (Random Access Memory), is the computer’s primary storage area that the CPU uses to store data and programs while they are being used. This is the computer’s short-term memory, where data is stored temporarily while programs are running. RAM is volatile, so it loses its contents when the power is turned off. It provides fast access to the CPU, allowing the computer to perform tasks efficiently. The more RAM a computer has, the more data and applications it can handle simultaneously, improving overall performance.

Whenever the user wants to run any program (Program Files), it should be brought into the main memory so the CPU can execute it. Your Program File is stored on the HARD DISK, and the CPU cannot access the HARD Disk directly. CPU can access the Main memory. So, the Program (Program File) must be brought from the Hard Disk into the Main Memory so the CPU can execute it. This is why Main memory is also called Working Memory or Primary Memory.

Once the program is brought to the Main memory, then only the CPU executes the program line by line. So, whatever program we run, they are brought into the Main memory. If the program needs data from the keyboard or has to display some data on the monitor, then it can utilize the INPUT and OUTPUT devices.

Input Devices:

These devices allow users to interact with the computer, entering data and commands through devices like keyboards, mice, scanners, cameras, and microphones. These devices are used to give inputs to the computer. Input devices have their own memory in the computer called Input Buffer. All instructions from input devices are dumped into this memory, and if the program wants to read something, it will read from the input buffer. So, whatever we type using the keyboard will be stored in the input buffer, and the program reads the input from the input buffer.

Output Devices:

Output devices are peripherals that receive data from a computer and translate it into a form understandable to the user or another device. They allow the computer to communicate with the user or other systems. Common output devices include monitors (for displaying visual information), printers (for printing documents), speakers (for sound), and projectors. Output devices also have their own memory, which is called output buffers. If the program wants to print something, then whatever it wants to print will be put in the output buffer, which will appear on the output screen.

How It All Works Together?

When a user runs an application:

  • The operating system loads the application from storage into RAM.
  • The CPU fetches and executes the application’s instructions, using input data as needed.
  • The application processes the data, producing output.
  • The output is sent to an output device (e.g., display on the monitor) or stored in long-term storage.

This is a very high-level overview, and each component and step involves intricate processes and technologies. The actual working of a computer includes numerous additional details, such as the motherboard, power supply, cooling systems, and the binary system that underpins all computer operations.

These are the components of a computer system, and this is how a program works inside it. You might have one question about how a computer understands the programming language or instructions. So, let’s look at it. The computer only understands the binary number system.

Introduction to Number System

Firstly, let us know why we need to understand the Number System while learning a programming language. The Number System we Human Beings follow is the Decimal number system, but the computer understands only the Binary Number System. So again, there is a difference between how we saw the number and how the computer saw it.

Example:

Firstly, let us know why we need to understand the Number System while learning a programming language. The Number System we Human Beings follow is the Decimal number system, but the computer understands only the Binary Number System. So again, there is a difference between how we saw the number and how the computer saw it.

Example: As a human, if I say 10 (one zero), for me, it is Ten, but for the computer, it is two. So, it’s necessary to understand the different types of number systems. The different types of number systems are as follows:

  1. Binary Number System: {0,1}
  2. Octal Number System: {0,1,2,3,4,5,6,7}
  3. Decimal Number System: {0,1,2,3,4,5,6,7,8,9}
  4. Hexadecimal Number System: {0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F}

Basically, we use the decimal number system, and in the decimal number system, the pictures or figures or symbols are from 0 to 9, i.e., a total of 10 symbols. As we already discussed, the computer works on zeros and ones. So, for computers, there are only two symbols, and the binary number systems have only two symbols, i.e., 0 and 1.

In the decimal number system, once we have finished with the last symbol, i.e., 9, after 9, we use a combination of symbols (from 0 to 9). For example- 10, 11, 12, and so on. 10 combines two symbols, i.e., 1 and 0. Similarly, 11 is the combination of 1 and 1.

So, the point that you need to understand is that once we finish with the symbols, we can take the combination of symbols, and in the binary number system, the same methodology is also followed. To denote the new numbers, we need to combine two symbols, i.e., 1’s and 0’s.

For example, to denote 2 in the binary system, we will combine 1 and 0, i.e., 10. Don’t read it as ten; read it as one zero. For more details, please look at the following table, which shows the numbers from 0 to 16 in the Decimal, Binary, Hexadecimal, and Octal number system.

Introduction to Number System

The above table gives how we see numbers in each number system. However, one thing here is common: when we exceed the number, then the combination of numbers will come. For Example, in the decimal system, 0 to 9 after nine, ten combines first and second, i.e., 0, and 1, i.e., 10.

How do we Convert Decimal Numbers to Binary Numbers?

For example- 29 is the decimal number; let’s see how we can convert this decimal number into a binary number. The base for the binary number is 2; hence, we need to perform successive division 2, take the remainder, and then read the remainder from bottom to top to get the binary number, as shown in the image below.

How do we Convert Decimal Numbers to Binary Numbers?

This is how a decimal number is converted into binary. Now, we will see how to convert a binary number to decimal form. For example – 10101 is the binary number, and we need to find its equivalent decimal number. To better understand how to convert, please look at the following diagram.

How does the computer works

So, this is how we can convert a binary number to a decimal number. We have seen how to convert decimal numbers to binary and binary numbers back to decimals.

In the next article, I will briefly introduce Programming Languages. Here, in this article, I try to explain how a computer works in detail, and I hope you enjoy this How does the computer work article.

3 thoughts on “How Computer Works”

Leave a Reply

Your email address will not be published. Required fields are marked *