Introduction

Every photo you take, every message you send, and every song you stream is stored inside a computer as nothing more than a long sequence of 0s and 1s. How does a machine that only understands two symbols handle letters, colours, sounds, negative numbers, and decimals?
The answer lies in data representation and number systems. In this tutorial you will learn how computers store information, how the binary, octal, decimal, and hexadecimal number systems work, how to convert between them step by step, and how computers represent negative numbers, real numbers, and text. Worked examples and practice questions are included at the end.
What Is Data Representation?
Data representation refers to the methods used to encode information so that a computer can store, process, and transmit it. Computers are built from digital circuits, and each circuit has only two reliable states: on and off (high voltage and low voltage). Two states are easy to build, fast to switch, and resistant to electrical noise, so every type of data, whether numbers, characters, images, or audio, is converted into patterns of 0s and 1s before the computer works with it.
The same pattern of bits can mean different things depending on how it is interpreted. The bits 01000001 can be the number 65, the letter “A”, or part of a pixel’s colour. The computer does not “know” which one; the program and the file format decide how to read the bits.
Bits, Bytes, and Larger Units
A single binary digit is called a bit (short for binary digit). It is the smallest unit of data and holds either 0 or 1. Bits are grouped into larger units:
| Unit | Size |
|---|---|
| Bit | 1 binary digit (0 or 1) |
| Nibble | 4 bits |
| Byte | 8 bits |
| Kilobyte (KB) | 1,024 bytes |
| Megabyte (MB) | 1,024 KB |
| Gigabyte (GB) | 1,024 MB |
| Terabyte (TB) | 1,024 GB |
Some manufacturers and standards use 1,000 instead of 1,024 for these prefixes (the 1,024 versions are formally called KiB, MiB, GiB). That is why a “500 GB” drive can show up as a slightly smaller number in your operating system.
A useful rule: n bits can represent 2n different values. One byte (8 bits) can therefore represent 28 = 256 values, from 0 to 255.
Number Systems Overview
A number system is a way of writing numbers using a fixed set of symbols. The number of distinct symbols is called the base (or radix). Four systems matter in computing:
- Binary (Base 2): uses two digits, 0 and 1.
- Octal (Base 8): uses eight digits, 0 to 7.
- Decimal (Base 10): uses ten digits, 0 to 9. This is the system used in everyday life.
- Hexadecimal (Base 16): uses sixteen symbols, 0 to 9 and A to F, where A = 10, B = 11, C = 12, D = 13, E = 14, and F = 15.
Positional Notation: The Idea Behind Every System
All four systems are positional: the value of a digit depends on its position. Each position is a power of the base, counted from the right starting at 0. In decimal, the number 254 means:
254 = 2 × 102 + 5 × 101 + 4 × 100 = 200 + 50 + 4
Binary, octal, and hexadecimal work in exactly the same way, only with a different base. Once you understand this, every conversion in this tutorial follows from one idea. To avoid confusion, the base is often written as a subscript: 11012 is binary, 1458 is octal, 25410 is decimal, and 1A316 is hexadecimal.
Quick Reference: 0 to 15 in All Four Systems
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
Notice that every hexadecimal digit lines up with exactly four binary digits, and every octal digit with exactly three. This is the reason these two systems exist, as explained later.
Binary Number System (Base 2)
Binary is the backbone of computer data representation. Each position holds a bit, and each position is worth a power of 2, so the place values from right to left are 1, 2, 4, 8, 16, 32, 64, 128, and so on.
Converting Binary to Decimal
Multiply each bit by 2 raised to the power of its position (counted from the right, starting at 0), then add the results.
Example: convert 11012 to decimal.
11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 8 + 4 + 0 + 1 = 13
Another example: 1011012 = 32 + 0 + 8 + 4 + 0 + 1 = 45
Converting Decimal to Binary
Use repeated division by 2:
- Divide the number by 2 and record the remainder (0 or 1).
- Divide the quotient by 2 again and record the new remainder.
- Repeat until the quotient is 0.
- Read the remainders from bottom to top (the last remainder is the leftmost bit).
Example: convert 13 to binary.
| Division | Quotient | Remainder |
|---|---|---|
| 13 ÷ 2 | 6 | 1 |
| 6 ÷ 2 | 3 | 0 |
| 3 ÷ 2 | 1 | 1 |
| 1 ÷ 2 | 0 | 1 |
Reading the remainders from bottom to top gives 1101, so 1310 = 11012.
Octal Number System (Base 8)
Octal uses the digits 0 to 7, and each position is a power of 8. It was widely used in early computers whose word sizes were multiples of three bits. Today its best-known use is in Unix and Linux file permissions, such as chmod 755.
Example: convert 1458 to decimal.
1458 = 1 × 82 + 4 × 81 + 5 × 80 = 64 + 32 + 5 = 101
To convert decimal to octal, use repeated division by 8 and read the remainders from bottom to top, the same method as for binary.
Decimal Number System (Base 10)
Decimal is the system we use for everyday arithmetic. It has ten digits, 0 to 9, and each place value is a power of 10. It is probably the dominant system because humans have ten fingers, not because it is mathematically special. Computers do not natively use decimal, so decimal numbers must be converted to binary for processing and back again for display.
Hexadecimal Number System (Base 16)
Hexadecimal (or “hex”) uses sixteen symbols: 0 to 9 for the values zero to nine, and A to F for the values ten to fifteen. Because one hex digit stands for exactly four bits, hex is a compact and readable way to write long binary numbers.
Example: convert 1A316 to decimal.
1A316 = 1 × 162 + 10 × 161 + 3 × 160 = 256 + 160 + 3 = 419
Note that the digit A is worth 10 in the calculation. To convert decimal to hexadecimal, divide repeatedly by 16 and write remainders of 10 to 15 as the letters A to F.
Converting Between Binary, Octal, and Hexadecimal
Conversions between these three systems are easy because 8 = 23 and 16 = 24. No arithmetic is needed; you only regroup bits.
Hexadecimal to Binary
Replace each hex digit with its four-bit pattern.
1A316 → 1 = 0001, A = 1010, 3 = 0011 → 0001 1010 00112 (the leading zeros can be dropped: 1101000112)
Binary to Hexadecimal
Group the bits in sets of four, starting from the right (pad the leftmost group with zeros if needed), then convert each group.
110110112 → 1101 | 1011 → D | B → DB16
Octal to Binary and Binary to Octal
For octal, use groups of three bits instead of four.
1458 → 1 = 001, 4 = 100, 5 = 101 → 001 100 1012
110101102 → group from the right: 011 | 010 | 110 → 3 | 2 | 6 → 3268
As a check, 110101102 is 214 in decimal, and so are 3268 (3 × 64 + 2 × 8 + 6) and D616 (13 × 16 + 6). Converting between octal and hexadecimal is easiest by going through binary.
Why Use Different Number Systems?
- Binary maps directly onto the on/off states of digital circuits, so it is the language the hardware actually uses.
- Hexadecimal gives humans a compact way to read and write binary. The byte 11011011 is DB in hex: eight digits become two. Typical uses include colour codes (such as
#FF5733), memory addresses, and MAC addresses. - Octal compresses binary three bits at a time. It survives mainly in Unix file permissions, where
755means read/write/execute for the owner and read/execute for everyone else. - Decimal is for people. Programs accept and display decimal values, and the computer converts them behind the scenes.
Computers always work in binary internally. Hexadecimal and octal are conveniences for humans, not for the machine.
Binary Addition
Binary arithmetic follows the same column-by-column method as decimal, but with only four basic rules:
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (write 0, carry 1)
Example: add 10112 (11) and 01102 (6).
Working from the right: 1 + 0 = 1; 1 + 1 = 0, carry 1; 0 + 1 + 1 (carry) = 0, carry 1; 1 + 0 + 1 (carry) = 0, carry 1; the final carry becomes the leftmost bit. The result is 100012 = 17, which matches 11 + 6.
Representing Negative Numbers
So far every number has been positive. Computers have no minus sign, so negative numbers must also be encoded in bits. Three methods are commonly taught:
- Sign-magnitude: the leftmost bit is the sign (0 = positive, 1 = negative) and the remaining bits hold the value. It is simple, but it gives two representations of zero (+0 and −0).
- One’s complement: a negative number is formed by flipping every bit of the positive number. It also has two zeros.
- Two’s complement: flip every bit and add 1. This is what modern computers use.
Two’s Complement
Two’s complement has one zero, and addition and subtraction work with the same circuitry for both positive and negative numbers. To represent −5 in 8 bits:
- Write +5 in binary: 00000101
- Flip all the bits: 11111010
- Add 1: 11111011
So −5 is stored as 11111011. The leftmost bit is 1, which signals a negative number. With n bits, two’s complement can represent values from −2n−1 to 2n−1 − 1, so 8 bits cover −128 to +127. As a check, adding 5 and −5 gives 00000101 + 11111011 = 1 00000000; the carry out of the eighth bit is discarded, leaving 0.
Floating Point Representation
Integers cannot hold fractions. For real numbers such as 6.5 or 0.000123, computers use floating point representation, which works like scientific notation: a number is stored as a sign, a scaling exponent, and a set of significant digits. This lets the same number of bits cover a huge range, from extremely large to extremely small values.
The standard format is IEEE 754. A 32-bit (single precision) number is split into three fields:
| Field | Single precision (32-bit) | Double precision (64-bit) |
|---|---|---|
| Sign | 1 bit | 1 bit |
| Exponent | 8 bits (bias 127) | 11 bits (bias 1023) |
| Mantissa (fraction) | 23 bits | 52 bits |
The stored value is (−1)sign × 1.mantissa × 2(exponent − bias). The leading 1 before the binary point is implied, so it is not stored. The exponent is stored with a bias so that negative exponents can be represented without a separate sign.
Example: represent 6.5 in single precision.
- Convert to binary: 6 = 110 and 0.5 = 0.1, so 6.5 = 110.12.
- Normalize: 110.1 = 1.101 × 22.
- Sign = 0 (positive).
- Exponent = 2 + 127 = 129 = 100000012.
- Mantissa = 101 followed by zeros: 10100000000000000000000.
The 32 bits are 0 10000001 10100000000000000000000, which is 40D00000 in hexadecimal.
Precision Limits
Just as 1/3 cannot be written exactly in decimal (0.3333…), many simple decimal fractions cannot be written exactly in binary. The value 0.1 becomes an endless repeating binary fraction, so it is rounded when stored. This is why, in most programming languages, 0.1 + 0.2 does not equal exactly 0.3 but a value like 0.30000000000000004. When exact decimal results matter, for example in money calculations, programmers use integers (such as cents) or special decimal types instead of floating point.
Representing Text, Images, and Sound
Text: ASCII and Unicode
Characters are stored by assigning each one a number, called a code point. ASCII uses 7 bits (128 characters) for English letters, digits, punctuation, and control codes. For example, “A” is 65 (01000001), “a” is 97 (01100001), and the digit “0” is 48 (00110000). The word “Hi” is stored as 72 and 105, which is 01001000 01101001.
ASCII cannot represent most of the world’s scripts, so Unicode was created to assign a unique code point to characters from virtually every language, plus symbols and emoji. The most common way to store Unicode is UTF-8, which uses one to four bytes per character and stays compatible with ASCII for the first 128 characters.
Images
A digital image is a grid of tiny squares called pixels. In the common RGB model, each pixel stores three values (red, green, and blue), usually one byte each, so every colour component ranges from 0 to 255. That gives 256 × 256 × 256, about 16.7 million possible colours. The hex colour #FF5733 is simply three bytes: FF (255) red, 57 (87) green, and 33 (51) blue.
Audio
Sound is a continuous wave, so it is sampled: the wave’s height is measured many times per second and each measurement is stored as a number. CD-quality audio takes 44,100 samples per second, each stored in 16 bits. More samples per second and more bits per sample give better quality but larger files.
Practice Questions
Try these before checking the answers.
- Convert 1011012 to decimal.
- Convert 15610 to binary.
- Convert 2F16 to decimal.
- Convert 111100002 to hexadecimal.
- Convert 2758 to binary.
- Convert 25510 to hexadecimal.
- Write −3 in 8-bit two’s complement.
Show answers
- 32 + 8 + 4 + 1 = 45
- 10011100 (128 + 16 + 8 + 4 = 156)
- 2 × 16 + 15 = 47
- 1111 | 0000 = F0
- 2 = 010, 7 = 111, 5 = 101, so 010 111 101
- 255 = 15 × 16 + 15, so FF
- +3 = 00000011, flip = 11111100, add 1 = 11111101
Key Takeaways
- Computers store everything as bits because two-state circuits are simple and reliable; n bits can represent 2n values.
- Binary, octal, decimal, and hexadecimal are all positional systems; only the base changes.
- Decimal to another base uses repeated division; any base to decimal uses place values.
- Hex digits map to 4 bits and octal digits to 3 bits, which makes those conversions a simple regrouping.
- Negative integers use two’s complement, and real numbers use IEEE 754 floating point, which is approximate for many decimal fractions.
- Text, images, and audio are all encoded as numbers (character codes, pixel values, and samples) and stored in binary.
Conclusion
Understanding data representation explains how a machine built from simple on/off switches can handle numbers, text, pictures, and sound. Binary is how computers store and process data, while hexadecimal and octal give humans a compact way to read and write binary. Once you are comfortable with place values and conversions, topics such as memory addressing, character encoding, networking, and low-level programming become much easier to follow.
For more tutorials on this topic, visit TutorialsDestiny.