Learning Objectives
By the end of this chapter, you will be able to:
- Explain why computers use the binary system.
- Define bit and byte, and convert between storage units.
- Convert simple numbers between decimal and binary.
- Understand the purpose of character encoding standards.
- Differentiate between ASCII and Unicode.
- Describe how images, sound, and programs are represented.
How Computers Represent Data
Digital computers do not understand human language. At their most fundamental level, they can only understand two states: on and off. These two states are represented by the numbers 1 (on) and 0 (off). This two-digit number system is called the binary system.
All data—whether it’s text, numbers, images, or sound—must be translated into a series of 1s and 0s before a computer can process it.
flowchart TB
Raw["All Data Types<br/>(text, numbers, images)"] --> Binary["Binary Representation<br/>(0s and 1s)"]
Binary --> Bit["Bit"]
Bit --> Byte["Byte (8 bits)"]
Byte --> Encode["Character Encoding<br/>(ASCII / Unicode)"]
Byte --> Machine["Machine Code<br/>(via compiler/interpreter)"]
Figure 1: From Data to Binary Representation
Why binary? Electronic circuits can reliably tell the difference between two states (current on or off, high or low voltage, magnetized or not). Two states are simple, cheap, and resistant to errors, while distinguishing ten voltage levels for decimal digits would be unreliable.
Bits and Bytes
The basic units of data representation are:
- Bit (Binary Digit): The smallest unit of data in a computer. A bit can have a value of either 0 or 1.
- Nibble: A group of 4 bits.
- Byte: A group of 8 bits. A single byte can represent 256 different values (2^8). The byte is the standard unit used to measure storage capacity.
Storage capacities are measured in multiples of bytes:
- Kilobyte (KB): Approximately 1,000 bytes.
- Megabyte (MB): Approximately 1 million bytes.
- Gigabyte (GB): Approximately 1 billion bytes.
- Terabyte (TB): Approximately 1 trillion bytes.
In computing, these units are often counted in powers of 2: 1 KB = 1,024 bytes, 1 MB = 1,024 KB, and so on. Storage manufacturers use powers of 10 (1 KB = 1,000 bytes). Both are acceptable in exams if stated clearly.
| Unit | Binary value (power of 2) | Approximate decimal value |
|---|---|---|
| 1 KB | 2¹⁰ = 1,024 bytes | 1 thousand bytes |
| 1 MB | 2²⁰ bytes | 1 million bytes |
| 1 GB | 2³⁰ bytes | 1 billion bytes |
| 1 TB | 2⁴⁰ bytes | 1 trillion bytes |
Number systems
| System | Base | Digits used | Example |
|---|---|---|---|
| Binary | 2 | 0, 1 | 1101 |
| Octal | 8 | 0–7 | 15 |
| Decimal | 10 | 0–9 | 13 |
| Hexadecimal | 16 | 0–9 and A–F | D |
Hexadecimal is a short way to write binary: each hex digit equals 4 bits. It is used for colour codes in web design (e.g., #FF0000 is red) and memory addresses.
Worked conversions
Decimal to binary — divide by 2 and record remainders, reading from bottom to top. For 13: 13 ÷ 2 = 6 r 1; 6 ÷ 2 = 3 r 0; 3 ÷ 2 = 1 r 1; 1 ÷ 2 = 0 r 1. Reading upwards: 13 = 1101₂.
Binary to decimal — multiply each bit by its place value (1, 2, 4, 8, 16, …). For 1101: 1×8 + 1×4 + 0×2 + 1×1 = 13.
How many values? With n bits you can represent 2ⁿ values: 1 bit = 2, 4 bits = 16, 8 bits = 256, 16 bits = 65,536.
Representing Characters: ASCII and Unicode
To represent text (letters, numbers, and symbols), computers use character encoding standards. These standards assign a unique binary number to each character.
-
ASCII (American Standard Code for Information Interchange): An early and widely used standard. It uses 7 or 8 bits to represent each character. The original 7-bit ASCII can represent 128 characters, which is enough for all the uppercase and lowercase English letters, numbers, and common punctuation marks.
-
Unicode: A modern standard designed to represent every character from every language in the world. Unicode uses a variable number of bits, allowing it to represent over a million unique characters. It is the standard used on the internet and in all modern operating systems. The most common implementation of Unicode is UTF-8.
| Character | ASCII decimal code | Binary (8-bit) |
|---|---|---|
A |
65 | 01000001 |
a |
97 | 01100001 |
0 |
48 | 00110000 |
| Space | 32 | 00100000 |
Nepali text in Devanagari (for example, “नेपाल”) cannot be represented in ASCII. Unicode gives each Devanagari letter its own code (e.g., न is U+0928), which is why Nepali websites, apps, and documents use Unicode fonts. Older Nepali documents typed in non-Unicode fonts like Preeti often display as random English letters on other computers — a common practical problem solved by converting to Unicode.
| Aspect | ASCII | Unicode |
|---|---|---|
| Bits per character | 7 (or 8 in extended ASCII) | Variable (8 to 32 bits in UTF-8) |
| Characters | 128 (256 extended) | Over a million possible |
| Languages | English only | Almost all world languages, plus emoji |
| Use today | Legacy systems; subset of UTF-8 | Web, mobile, modern operating systems |
Representing Images and Sound
- Images are made of tiny dots called pixels. Each pixel’s colour is stored as numbers, commonly 24 bits (8 bits each for red, green, and blue), giving over 16 million colours. More pixels (higher resolution) and more bits per pixel mean larger files.
- Sound is recorded by sampling the sound wave many times per second (e.g., 44,100 samples per second for CD quality) and storing each sample as a number.
- Video is a sequence of images (frames) plus sound, usually compressed.
Worked example: an uncompressed 1920 × 1080 image with 24-bit colour needs 1920 × 1080 × 3 bytes ≈ 6.2 MB. Compression formats like JPEG reduce this to a few hundred KB.
Representing Programs
Just like data, computer programs (which are sets of instructions) must also be represented in binary. When a programmer writes code in a high-level language like Python or Java, a special program called a compiler or an interpreter translates that human-readable code into the binary machine code that the computer’s processor can directly execute.
Each machine instruction is a binary pattern: part of it (the opcode) says what to do (add, load, store), and the rest (the operand) says what data or memory address to use.
Summary
Computers represent all data and instructions in the binary system, using combinations of 0s and 1s, because electronic circuits reliably handle two states. The smallest unit of data is a bit, and 8 bits make up a byte, which is the standard measure of storage. Numbers can be converted between binary, decimal, and hexadecimal. To represent text, computers use character encoding standards like ASCII for basic English text and Unicode for all international languages, including Nepali. Images are stored as pixels and sound as samples. Even the programs we write must be compiled down to binary machine code before a computer can run them.
Key Takeaways
- Computers use the binary system (0s and 1s) to represent all data.
- A bit is a single binary digit; a byte is 8 bits; n bits can represent 2ⁿ values.
- ASCII and Unicode are standards for encoding text characters into binary numbers.
- Unicode is the modern standard that supports all world languages, including Nepali.
- Images are stored as pixels, sound as samples, and programs as binary machine instructions.
Discussion Questions
- Why is the binary system a natural fit for electronic computers?
- A standard text message (SMS) is limited to 160 characters. If it uses 7-bit ASCII encoding, how many bits are in a maximum-length message?
- Why was it necessary to create Unicode to replace ASCII?
Exam-Style Questions
Short answer
- Define bit and byte. How many bytes are in 1 KB?
- Convert 25 (decimal) to binary and
10110(binary) to decimal. - Differentiate between ASCII and Unicode.
Long answer
- Explain how computers represent numbers, text, images, and sound.
- What are character encoding standards? Why is Unicode important for languages like Nepali?

