Data Representation in Computer Science Study Guide

Foundations of Data Representation and Number Systems

In the field of computer science, specifically within the O Level (2210) and IGCSE (0478) curriculum, data representation is the fundamental concept of how information is processed and stored. Computers operate using the binary number system because they are constructed using digital circuits that recognize only two distinct states: on and off. These states are represented numerically as 11 and 00. Insideทุก computer, there are microscopic components known as logic gates, such as the NOT gate, which act as traffic controllers for binary data, ensuring the smooth flow of information. To facilitate immediate processing, the Central Processing Unit (CPU) utilizes registers. Registers are specialized, high-speed memory locations used to quickly accept, store, and transfer data and instructions that are currently in use. They function as temporary storage boxes that hold bits until they are required for a specific operation.

The Denary and Binary Number Systems

The denary system, also referred to as the decimal system, is the base 1010 numerical language used in daily life. In this system, each digit's value is determined by its position, which represents a power of ten. For instance, in the number 20242024, the rightmost digit occupies the 10010^0 position (11), the next is 10110^1 (1010), followed by 10210^2 (100100), and 10310^3 (10001000). The calculation is expressed as (2×103)+(0×102)+(2×101)+(4×100)=2024(2 \times 10^3) + (0 \times 10^2) + (2 \times 10^1) + (4 \times 10^0) = 2024.

Binary is a base 22 system, meaning it counts in powers of two. The value of a binary digit (bit) depends on its position: the rightmost bit represents 202^0 (11), the next represents 212^1 (22), the next 222^2 (44), and so on. A binary value of 11 indicates that the power of two at that specific position is included in the total sum, while a 00 indicates it is excluded. For example, the binary number 11011101 is calculated as (1×23)+(1×22)+(0×21)+(1×20)=8+4+0+1=13(1 \times 2^3) + (1 \times 2^2) + (0 \times 2^1) + (1 \times 2^0) = 8 + 4 + 0 + 1 = 13. To convert a denary number like 5454 into binary, one must identify the powers of two that sum to that value. The nearest power of two less than or equal to 5454 is 3232. The breakdown is 32+16+4+2=5432 + 16 + 4 + 2 = 54, resulting in the binary representation 110110110110. When working with 8-bit registers, this would be padded with leading zeros to become 0011011000110110.

The Hexadecimal Number System

Hexadecimal is a base 1616 system where each digit represents values from 00 to 1515. To represent values beyond 99 with a single character, letters are used: 1010 is AA, 1111 is BB, 1212 is CC, 1313 is DD, 1414 is EE, and 1515 is FF. Hexadecimal is highly beneficial as a shorthand for binary because it is easier and quicker for humans to read, easier to debug, takes up less screen space, and reduces the likelihood of manual entry errors. Common applications include defining memory addresses, writing assembly language, and representing color values in web design.

Converting between hexadecimal and denary involves powers of 1616. For example, to convert 2FA02FA0 to denary: (2×163)+(15×162)+(10×161)+(0×160)=8192+3840+160+0=12192(2 \times 16^3) + (15 \times 16^2) + (10 \times 16^1) + (0 \times 16^0) = 8192 + 3840 + 160 + 0 = 12192. To convert denary to hexadecimal, such as the number 198198, one can use repeated division by 1616. 198/16=12198 / 16 = 12 with a remainder of 66. Then, 12/16=012 / 16 = 0 with a remainder of 1212. In hexadecimal, 1212 is represented as CC. Reading the remainders from bottom to top gives the value C6C6. Alternatively, one can convert binary to hexadecimal by first converting the binary to denary and then to hexadecimal, or vice versa.

Binary Arithmetic, Overflow, and Logical Shifts

Binary addition follows specific rules: 0+0=00 + 0 = 0, 0+1=10 + 1 = 1, 1+0=11 + 0 = 1, and 1+1=101 + 1 = 10 (which is 00 with a carry of 11). If three bits are added (such as 1+1+carry 11 + 1 + \text{carry } 1), the result is 1111 (which is 11 with a carry of 11). An overflow error occurs when the result of an arithmetic operation exceeds the predefined limit of the register. In an 8-bit system, the maximum representable value is 1111111111111111, which equals 255255 in denary. If the sum of two 8-bit numbers requires a 9th bit, that bit is lost, leading to an incorrect result.

Logical binary shifts involve moving all bits within a binary number left or right. In a logical left shift, bits move left, and a 00 is inserted at the rightmost position. A left shift by one bit effectively multiplies the number by 22. Conversely, a logical right shift moves bits to the right, inserting a 00 at the leftmost position, which divides the number by 22 (discarding any remainder). During these shifts, any bits moved outside the boundaries of the register (the most significant bit in a left shift or the least significant bit in a right shift) are permanently lost.

Two's Complement for Signed Integers

Two's complement is a method used to represent both positive and negative integers in binary. In an 8-bit two's complement system, the leftmost bit (the 8th bit) is the sign bit and has a value of 128-128. If the sign bit is 00, the number is positive; if it is 11, the number is negative. The range for an 8-bit two's complement integer is from 128-128 to +127+127. To represent a negative number like 23-23, one method is to take the positive binary representation of 2323 (0001011100010111), invert all the bits (1110100011101000), and then add 11 (1110100111101001). Summing the place values of 1110100111101001 confirms the result: 128+64+32+8+1=23-128 + 64 + 32 + 8 + 1 = -23.

Representation of Text, Sound, and Images

Text is represented in computers using character sets, which assign unique numbers to every symbol. ASCII (American Standard Code for Information Interchange) uses 77 bits per character, providing 128128 unique codes. Because ASCII is limited to English, Unicode was developed. Unicode uses more bits (often 1616 bits), allowing for approximately 44 billion characters, covering diverse languages and emojis.

Sound is represented by sampling an analogue sound wave. This involves measuring the amplitude of the wave at regular intervals and converting those measurements into binary. The sample rate is the number of samples taken per second, measured in Hertz (Hz). The sample resolution (or bit depth) is the number of bits used to represent each sample. Increasing the sample rate and resolution improves the accuracy and quality of the recording but increases the file size.

Digital images are composed of pixels, the smallest units of an image. Resolution refers to the total number of pixels (width ×\times height). Colour depth is the number of bits used per pixel to represent its color; for example, an 8-bit depth allows for 28=2562^8 = 256 colors. Higher resolution and color depth result in better image quality but significantly larger file sizes.

Data Storage Units and Calculations

Data storage is measured in specific units: a bit is the smallest unit (00 or 11), a nibble is 44 bits, and a byte is 88 bits. The curriculum distinguishes between binary units (base 22) and decimal units (base 1010). Binary units use a factor of 10241024: 1024 bytes=1 kibibyte (KiB)1024 \text{ bytes} = 1 \text{ kibibyte (KiB)}, 1024 KiB=1 mebibyte (MiB)1024 \text{ KiB} = 1 \text{ mebibyte (MiB)}, and so on through gibibyte (GiB), tebibyte (TiB), pebibyte (PiB), and exbibyte (EiB). Decimal units like kilobyte (KB) use a factor of 10001000.

To calculate the file size of an image, use the formula: width×height×colour depth\text{width} \times \text{height} \times \text{colour depth}. For an image 150 pixels wide,100 pixels high150 \text{ pixels wide}, 100 \text{ pixels high}, and 16-bit colour16\text{-bit colour}, the size is (150×100×16)/8=30000 bytes(150 \times 100 \times 16) / 8 = 30000 \text{ bytes}. For a sound file, the calculation is: sample rate×sample resolution×length in seconds\text{sample rate} \times \text{sample resolution} \times \text{length in seconds}. For a 30-second30\text{-second} clip with a 40 kHz40 \text{ kHz} rate and 8-bit8\text{-bit} resolution, the size in MiB is calculated as: (40000×8×30)/8/1024/1024×approximately 1.14 MiB(40000 \times 8 \times 30) / 8 / 1024 / 1024 \times \text{approximately } 1.14 \text{ MiB}.

Data Compression Techniques

Data compression is essential to reduce file sizes, which saves storage space, reduces the bandwidth required for transmission, and shortens transmission times. There are two main types: Lossy and Lossless. Lossy compression permanently removes data to significantly reduce size (e.g., JPEG for images, MP3 for audio). This involves reducing resolution, color depth, or bit depth. Lossless compression reduces size without any data loss, which is vital for text files and executables (e.g., ZIP, PNG). Run Length Encoding (RLE) is a lossless method that replaces repeated sequences of data with a single value and a count. For example, "AAAABBBCCDAA" compresses to "4A3B2C1D2A".