Show understanding of different number systems

Resources | Subject Notes | Computer Science | Lesson Plan

Data Representation - A-Level Computer Science

1.1 Data Representation

This section explores how data is represented in binary form, which is fundamental to how computers store and process information. We will cover various number systems and their conversions.

Number Systems

Computers primarily use the binary number system. However, we often need to represent numbers in other systems, such as decimal, octal, and hexadecimal. Understanding the relationships between these systems is crucial.

Binary (Base-2)

Binary is the fundamental language of computers. It uses only two digits: 0 and 1. Each digit is called a bit.

Decimal (Base-10)

Decimal is the number system we use in everyday life. It uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Each position in a decimal number represents a power of 10.

Octal (Base-8)

Octal uses eight digits: 0, 1, 2, 3, 4, 5, 6, 7. Each position in an octal number represents a power of 8.

Hexadecimal (Base-16)

Hexadecimal uses sixteen digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, where A=10, B=11, C=12, D=13, E=14, and F=15. Each position in a hexadecimal number represents a power of 16.

Conversion between Number Systems

We can convert between different number systems using various methods.

Binary to Decimal

To convert a binary number to decimal, multiply each bit by the corresponding power of 2 and sum the results.

Example: $1011_2 = (1 \times 2^3) + (0 \times 2^2) + (1 \times 2^1) + (1 \times 2^0) = 8 + 0 + 2 + 1 = 11_{10}$

Decimal to Binary

To convert a decimal number to binary, repeatedly divide the number by 2 and record the remainders. The remainders, read in reverse order, form the binary equivalent.

Example: $25_{10}$

  1. $25 \div 2 = 12$ remainder $1$
  2. $12 \div 2 = 6$ remainder $0$
  3. $6 \div 2 = 3$ remainder $0$
  4. $3 \div 2 = 1$ remainder $1$
  5. $1 \div 2 = 0$ remainder $1$

Reading the remainders in reverse order gives $11001_2$

Binary to Hexadecimal

To convert binary to hexadecimal, group the binary digits into groups of four, starting from the right. Then, convert each group of four binary digits to its hexadecimal equivalent.

Example: $11010110_2$

Suggested diagram: Illustrating the grouping of binary digits into groups of four for hexadecimal conversion.

$1101 \ 0110_2 = D \ 6_{16}$

Hexadecimal to Binary

To convert hexadecimal to binary, convert each hexadecimal digit to its four-bit binary equivalent and concatenate the results.

Example: $2A_ {16}$

$2_{16} = 0010_2$

$A_{16} = 1010_2$

$2A_{16} = 0010 \ 1010_2 = 101010_2$

Decimal to Hexadecimal

To convert decimal to hexadecimal, repeatedly divide the number by 16 and record the remainders. The remainders, read in reverse order, form the hexadecimal equivalent. If a remainder is 10, 11, 12, 13, 14, or 15, it is represented by A, B, C, D, E, or F, respectively.

Example: $25_{10}$

  1. $25 \div 16 = 1$ remainder $9$ (which is $9_{16}=9_{16}$)
  2. $1 \div 16 = 0$ remainder $1$

$25_{10} = 19_{16}$

Data Representation in Computers

In a computer, data is typically stored as binary. Different data types are represented using specific numbers of bits.

Data Type Size (bits) Range Example
Byte 8 0 to 255 Any character, small integer
Half-Byte (Nibble) 4 0 to 15 Represents a part of a character
Word 16 0 to 65535 Larger integer, address
Double Word 32 0 to 4294967295 Large integer, memory address

Encoding

Characters and other symbols are encoded into binary using various encoding schemes. A common example is ASCII (American Standard Code for Information Interchange), which uses 7 bits to represent 128 characters.

Other encoding schemes include Unicode, which supports a wider range of characters.