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 and . 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 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 , the rightmost digit occupies the position (), the next is (), followed by (), and (). The calculation is expressed as .
Binary is a base system, meaning it counts in powers of two. The value of a binary digit (bit) depends on its position: the rightmost bit represents (), the next represents (), the next (), and so on. A binary value of indicates that the power of two at that specific position is included in the total sum, while a indicates it is excluded. For example, the binary number is calculated as . To convert a denary number like into binary, one must identify the powers of two that sum to that value. The nearest power of two less than or equal to is . The breakdown is , resulting in the binary representation . When working with 8-bit registers, this would be padded with leading zeros to become .
The Hexadecimal Number System
Hexadecimal is a base system where each digit represents values from to . To represent values beyond with a single character, letters are used: is , is , is , is , is , and is . 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 . For example, to convert to denary: . To convert denary to hexadecimal, such as the number , one can use repeated division by . with a remainder of . Then, with a remainder of . In hexadecimal, is represented as . Reading the remainders from bottom to top gives the value . 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: , , , and (which is with a carry of ). If three bits are added (such as ), the result is (which is with a carry of ). 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 , which equals 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 is inserted at the rightmost position. A left shift by one bit effectively multiplies the number by . Conversely, a logical right shift moves bits to the right, inserting a at the leftmost position, which divides the number by (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 . If the sign bit is , the number is positive; if it is , the number is negative. The range for an 8-bit two's complement integer is from to . To represent a negative number like , one method is to take the positive binary representation of (), invert all the bits (), and then add (). Summing the place values of confirms the result: .
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 bits per character, providing unique codes. Because ASCII is limited to English, Unicode was developed. Unicode uses more bits (often bits), allowing for approximately 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 height). Colour depth is the number of bits used per pixel to represent its color; for example, an 8-bit depth allows for 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 ( or ), a nibble is bits, and a byte is bits. The curriculum distinguishes between binary units (base ) and decimal units (base ). Binary units use a factor of : , , and so on through gibibyte (GiB), tebibyte (TiB), pebibyte (PiB), and exbibyte (EiB). Decimal units like kilobyte (KB) use a factor of .
To calculate the file size of an image, use the formula: . For an image , and , the size is . For a sound file, the calculation is: . For a clip with a rate and resolution, the size in MiB is calculated as: .
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".