Computers are digital machines that store and process all information using only two symbols: 0 and 1. Each such symbol is called a binary digit or a bit. Every number, character, image, sound and video that a computer handles is ultimately reduced to a sequence of bits. This chapter explains how numbers are represented in binary form, how different number systems are related, how negative numbers and fractional numbers are stored, and how text characters are encoded using standard codes. Understanding data representation is essential because it reveals how a computer actually interprets the information given to it by a programmer.
There are four main number systems used in computing: decimal (base 10), binary (base 2), octal (base 8) and hexadecimal (base 16). Each system has a base or radix that tells how many distinct symbols it uses. Decimal uses the digits 0 to 9, binary uses 0 and 1, octal uses 0 to 7, and hexadecimal uses 0 to 9 followed by A to F (representing values 10 to 15). A computer works internally in binary because digital electronic circuits have only two stable states, corresponding to a high voltage and a low voltage.
In addition to positional number systems, the chapter covers the representation of negative numbers using one's and two's complement, and the storage of real numbers using the IEEE floating-point format. It also introduces character encoding standards: ASCII, ISCII and Unicode, which allow text from many languages to be represented in a machine-readable form. A solid grip on these ideas is required for later chapters on Boolean logic and computer arithmetic.
A number system defines a set of symbols and rules for representing numbers. In a positional number system, the value of a digit depends on its position. The position of a digit multiplies its value by a power of the base.
The decimal system uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Each digit's value depends on its position. For example, the number 2456 means: (2 x 10^3) + (4 x 10^2) + (5 x 10^1) + (6 x 10^0) = 2000 + 400 + 50 + 6 = 2456.
The binary system uses only two digits, 0 and 1. This is the natural language of digital computers. For example, the binary number 10110 means: (1 x 2^4) + (0 x 2^3) + (1 x 2^2) + (1 x 2^1) + (0 x 2^0) = 16 + 0 + 4 + 2 + 0 = 22 in decimal.
The octal system uses eight digits: 0 to 7. It is convenient because 8 = 2^3, so each octal digit corresponds to exactly three binary bits. The octal number 245 means: (2 x 8^2) + (4 x 8^1) + (5 x 8^0) = 128 + 32 + 5 = 165 in decimal.
The hexadecimal system uses sixteen symbols: 0 to 9 and A to F, where A=10, B=11, C=12, D=13, E=14, F=15. Since 16 = 2^4, each hexadecimal digit corresponds to exactly four binary bits. The hexadecimal number 2AF means: (2 x 16^2) + (10 x 16^1) + (15 x 16^0) = 512 + 160 + 15 = 687 in decimal. Hexadecimal is widely used in memory addresses and colour codes because of its compactness.
Conversion between number systems is an important skill. Below are the standard methods.
Repeatedly divide the decimal number by 2 and record the remainders from bottom to top. For example, to convert 45 to binary: 45 / 2 = 22 remainder 1; 22 / 2 = 11 remainder 0; 11 / 2 = 5 remainder 1; 5 / 2 = 2 remainder 1; 2 / 2 = 1 remainder 0; 1 / 2 = 0 remainder 1. Reading remainders bottom-up gives 101101. Hence 45 = 101101 in binary.
Multiply each bit by its positional power of 2 and add. For 1011: (1 x 2^3) + (0 x 2^2) + (1 x 2^1) + (1 x 2^0) = 8 + 0 + 2 + 1 = 11.
Use the same repeated-division method, dividing by 8 or 16 respectively. For example, 45 in octal: 45 / 8 = 5 remainder 5; 5 / 8 = 0 remainder 5, giving 55 in octal.
Because 8 = 2^3 and 16 = 2^4, conversions between binary and octal/hexadecimal are easy: - Binary to octal: Group the bits in threes starting from the rightmost bit, then convert each group. - Binary to hexadecimal: Group the bits in fours and convert each group. - Octal/hexadecimal to binary: Replace each digit by its 3-bit or 4-bit binary equivalent.
For example, the binary number 1101101 grouped as 110 110 1 -> 001 101 101 gives 155 in octal. Grouped as 110 1101 -> 0110 1101 gives 6D in hexadecimal.
Binary numbers can be added, subtracted, multiplied and divided using rules analogous to decimal arithmetic.
The rules are: 0 + 0 = 0; 0 + 1 = 1; 1 + 0 = 1; 1 + 1 = 0 with a carry of 1. For example, adding 1011 and 1101: 1011 + 1101 = 11000 (which is 24 in decimal, equal to 11 + 13).
The rules are: 0 - 0 = 0; 1 - 0 = 1; 1 - 1 = 0; 0 - 1 requires borrowing 1 from the next higher bit. For example, 1101 - 1011 = 0010 (13 - 11 = 2). Subtraction can also be performed by adding the two's complement of the subtrahend, which is the method actually used in computers.
Signed numbers can be represented in three ways: sign-magnitude, one's complement and two's complement.
The most significant bit (MSB) is used as a sign bit: 0 for positive and 1 for negative. The remaining bits store the magnitude. For example, in an 8-bit system, +45 is 00101101 and -45 is 10101101. This method is simple but has the drawback of two representations for zero (00000000 and 10000000).
Negative numbers are obtained by flipping every bit of the positive number (changing 0 to 1 and 1 to 0). For example, +45 = 00101101, so -45 = 11010010. Zero again has two representations.
The two's complement is obtained by adding 1 to the one's complement. For -45: one's complement of 00101101 is 11010010; adding 1 gives 11010011. The two's complement system is preferred because it has a single representation of zero, and subtraction can be performed simply by adding the two's complement. The range of values for an n-bit two's complement number is from -2^(n-1) to +2^(n-1) - 1.
Real numbers (numbers with a fractional part) are stored in floating-point form, which is analogous to scientific notation. A floating-point number has two parts: a mantissa (or significand) containing the significant digits, and an exponent showing the power of the base. For example, 1234.56 can be written as 0.123456 x 10^4, where 0.123456 is the mantissa and 4 is the exponent.
The most widely used standard is IEEE 754. In the single-precision (32-bit) format, 1 bit is used for the sign, 8 bits for the biased exponent, and 23 bits for the mantissa. In double-precision (64-bit) format, the allocation is 1 bit for sign, 11 bits for the exponent and 52 bits for the mantissa. Floating-point representation allows a huge range of values, but because the mantissa has limited precision, some decimal fractions (such as 0.1) cannot be stored exactly. This is why computations with floating-point numbers often produce tiny rounding errors.
Numbers alone are not enough; computers must also store text. Character encoding maps each character to a unique code.
The American Standard Code for Information Interchange (ASCII) uses 7 bits, giving 128 codes for English letters, digits, punctuation and control characters. For example, 'A' is 65, 'a' is 97 and '0' is 48. An extended 8-bit version provides 256 codes.
The Indian Script Code for Information Interchange (ISCII) was developed to represent Indian languages such as Hindi, Tamil and Bengali. It is an 8-bit code that can encode characters of all major Indian scripts.
Unicode is a universal encoding standard that represents characters from virtually every written language in the world, including emojis and symbols. UTF-8, a popular Unicode encoding, uses a variable number of bytes per character so that ASCII text remains compatible. For example, the Hindi character "рдХ" and the English letter "A" both have unique Unicode code points. Unicode solves the problem of representing multiple scripts in a single document.
| Number System | Base | Digits Used | Example |
|---|---|---|---|
| Decimal | 10 | 0-9 | 245 |
| Binary | 2 | 0, 1 | 11110101 |
| Octal | 8 | 0-7 | 365 |
| Hexadecimal | 16 | 0-9, A-F | F5A2 |
| Character | ASCII Code |
|---|---|
| A | 65 |
| Z | 90 |
| a | 97 |
| z | 122 |
| 0 | 48 |
| 9 | 57 |
| space | 32 |
Data representation is the bridge between human information and machine storage. Binary numbers are the native language of computers, while octal and hexadecimal provide convenient shorthand. Negative numbers are handled elegantly using two's complement, and real numbers use the floating-point format with its inherent trade-off between range and precision. Character codes such as ASCII, ISCII and Unicode enable computers to store and exchange text across the world. These concepts underpin everything a computer does; in the next chapter we will see how the same binary logic is organised into gates and boolean algebra, which form the electronic heart of the processor.