Fundamentals of Computer Science: Data Representation and Manipulation
Representation of Audio
Analogue Information:
Continuously variable data representing natural phenomena such as sight and hearing.
Real numbers (numbers with decimal points) are used to represent analogue information.
Data Derived from Analogue Information:
Computers often handle data derived from analogue sources, including:
Audio (e.g. music, speech)
Images (e.g. diagrams, photographs)
Video (which includes both images and audio).
Audio Signal Representation:
Audio signals can be represented as a series of numbers denoting the value of the signal at consecutive points.
Example of Waveform Representation:
A waveform can be represented by a bit string, such as:
0001 1001 1111 1010 0101.
Factors Affecting Quality of Digitized Signal:
Frequency:
Refers to the number of samples taken per second.
Accuracy:
Denotes the number of bits used for each sample.
Importance of Sampling Rate:
If the sampling rate is too slow, the representation might not accurately depict the original signal.
Example: A graph showing a distorted sound signal, which does not match the original.
A/D Conversion
Analogue to Digital and Digital to Analogue Conversion:
Conversion between analogue signals and binary data is performed by electronic components known as A/D (Analogue to Digital) and D/A (Digital to Analogue) converters.
Sound File Formats on Windows:
.wavfiles store audio as a simple list of data values with a defined sample rate.Audio CDs contain uncompressed lists of data values with additional error-checking information.
Compressed formats (e.g.
mp3) utilize sophisticated techniques to minimize the data required for audio representation.
Representation of Images
Bitmap Images:
Digital images often consist of individual pixels and are known as bitmap images.
Each image is represented as an array of numbers, with each number specifying the color of one pixel.
Vector Images:
An alternative representation to bitmap images is vector images, which use geometric shapes.
Color Representation:
Colors are typically represented using the RGB model:
Red, Green, and Blue combined in various amounts.
Example illustrating this can be found in online resources.
Additive vs. Subtractive Color
Additive Color Model:
Achieved by adding varying intensities of red, green, and blue light.
Subtractive Color Model:
Applies to paints and printing processes where colors are created by subtracting varying amounts of light.
Factors Affecting Image Data Requirements:
The amount of binary data necessary for image representation depends on:
Resolution:
Defined as the count of pixels the image contains.
Higher resolution allows for clearer images with finer details.
Color Depth:
Refers to the number of bits used to signify each pixel’s color.
For example, 3 bits/pixel gives 8 colors, while 24 bits/pixel provides 16 million colors, which is the standard for RGB images.
Calculating Image Size
Example Calculation:
Given an image of size 800x600 pixels with a color depth of 24 bits:
Formula:
Total pixels = 800 px (height) × 600 px (width) = 480,000 pixels.
Total bits = 480,000 pixels × 24 bits/pixel = 11,520,000 bits.
Convert to bytes:
Convert to KB:
Convert to MB:
Thus, the image requires 1.37 MB of memory space.
Manipulating Binary Data – The ALU
Data Manipulation:
In computer applications, data (including numbers, text, images) is manipulated via software instructions executed by the CPU.
Arithmetic Logic Unit (ALU):
The ALU within the CPU performs a variety of arithmetic and logical operations.
Binary Arithmetic
Binary Addition:
Functions similarly to decimal addition, with the notion of carrying applicable in both systems.
Example illustrated:
egin{array}{cccc}
& 1 & 1 \& 1 & 0 \
ext{(Decimal: 3 + 2)} \
= & 1 & 0 & 1 \
ext{(Decimal: 5)}
\end{array}
Carry Bit:
Utilized when the result of binary operations exceeds the storage capacity of CPU registers.
Specifically, the carry bit is kept in a separate memory location known as the carry flag.
Signed Binary Numbers – Two’s Complement Representation
Signed Number Representation:
Signed numbers (capable of being positive or negative) are normally encoded as Two’s Complement.
Two’s Complement Conversion:
To derive the two’s complement of a number, invert each bit and add one:
Example:
For positive 5 () - Invert to , then add 1 to get (representing -5).
Sign Bit Indicator:
The leftmost bit (most significant bit) serves as the sign bit, where:
‘0’ denotes positive values.
‘1’ denotes negative values.
Three-Bit Two’s Complement Table:
The following is a representation of three-bit two's complement values:
+3:
+2:
+1:
0:
-1:
-2:
-3:
-4:
Arithmetic Operations in Two’s Complement:
Subtraction can be performed using addition:
Arithmetic Overflow
Understanding Overflow:
Due to fixed-size CPU registers, arithmetic results must fit within specified bit limits.
For instance, using three bits to represent values limits us to a range of -4 to +3.
Attempting operations outside this range can yield incorrect results, an issue known as arithmetic overflow.
ALU Overflow Detection:
The ALU can recognize overflow scenarios and sets the overflow flag to ‘1’ whenever arithmetic overflow occurs.
Real-World Example:
The INS (Inertial Navigation System) encountered a runtime error when converting a 64-bit number to a 16-bit format without adequacy checks, leading to malfunctioning.
Representation of Real Numbers
Real Number Structure:
Real numbers consist of both whole and fractional components (e.g., 13725.00173).
As a simplification, a binary representation might use separate bits for whole and fractional parts, such as 32 bits each.
Precision Representation:
A configuration with 7 digits for whole parts and 3 for fractions can adequately represent larger numbers but may lead to rounding issues for smaller numbers, which necessitates more significant precision.
Floating Point Format for Real Numbers:
A common method to represent real numbers is using floating-point format:
General form:
Rules of Floating-Point Arithmetic
Operations Overview:
Addition/Subtraction:
Align exponents before performing the operation on the mantissae.
Multiplication/Division:
Combine exponents and manipulate mantissae accordingly.
Floating Point Examples
Calculating Addition and Multiplication:
Addition:
Multiplication:
Floating Point Unit (FPU):
Many CPUs possess an FPU to process floating-point operations, which typically require more time compared to integer operations.
Logical Operations
ALU Capabilities:
Beyond arithmetic, the ALU executes a range of logical operations including AND, OR, NOT, and XOR (exclusive OR), producing binary outputs of ‘1’ (TRUE) or ‘0’ (FALSE).
Logical Operations Examples:
AND:
A
B
A.B
0
0
0
0
1
0
1
0
0
1
1
1
OR:
A
B
A+B
0
0
0
0
1
1
1
0
1
1
1
1
NOT:
A
NOT A
0
1
1
0
XOR:
A
B
A+B
0
0
0
0
1
1
1
0
1
1
1
0
Boolean Operations in High-Level Languages:
Many languages like Python facilitate Boolean operations, as shown:
python A = True B = False print(A and B) # Output: False
Additional ALU Operations
Higher-Level Logical Operations:
SHIFT:
Moves bits in a register left or right.
ROTATE:
Similar to SHIFT but allows the displaced bits to wrap around.
Important for cryptographic processes.
COMPARE:
Compares contents of two registers, setting a status flag if they match.
Summary of Key Concepts
Representation of audio in binary data.
Representation of images in binary data.
Binary addition and its processes.
Representations of negative binary numbers – two's complement.
Representations of real numbers in binary data.
Details about the ALU and its role.
Implications of arithmetic overflow and recognition by the overflow flag.
Understanding logical operations AND, OR, XOR, and NOT, along with shift and rotate operations.