Data Representation
Data Representation
Chapter 1 - Data Representation
Number Systems
Binary System :
The binary system is crucial because all forms of information (text, images,
music) need to be converted into a binary format for processing by a
computer.
● On = Value of 1
● Off = Value of 0
Therefore, the binary system represents data using only two possible
values: 0 and 1.
In our daily lives, we use the denary system (base-10). Computers cannot
directly understand denary, so we must convert between denary and binary
to transmit data.
Hexadecimal System
Binary 2 0, 1
Denary 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
In hexadecimal, the values range from 0 to 9 and then from A to F, where A
represents 10, B represents 11, and so on, up to F representing 15.
Example:
If the leftmost chunk has fewer than four digits, add leading zeros to make
it a four-digit chunk. For example, convert 1011111101 to hexadecimal:
Example:
Convert the hexadecimal value 3A to binary.
1. Map each digit to its binary value:
● 3 = 0011
● A = 1010
Therefore, the binary equivalent of the hexadecimal value 3A is 00111010.
Denary to Hexadecimal
The process of converting denary to hexadecimal is similar to converting
denary to binary. When converting to binary, we continuously divide by 2
and read the remainders from bottom to top. For hexadecimal, we divide by
16 instead.
Multiply the digit value by its place value. The place values in hexadecimal
are powers of 16 (1, 16, 256, etc.).
HEMI Mnemonic
Here's a breakdown of the usages of hexadecimal, summarized by the
mnemonic HEMI:
● 0 + 0 = 0
● 0 + 1 = 1
● 1 + 0 = 1
● 1 + 1 = 10 (0 with a carry of 1)
● 1 + 1 + 1 = 11 (1 with a carry of 1)
●
Example:
1111001
+ 0011010
----------------------
10010011
Overflow Condition
The overflow condition occurs when the result of a binary addition requires
more bits than are available in the register (the component that stores the
value).
If a register can only store eight bits and an addition results in nine bits, the
extra bit will be lost, leading to an incorrect result.
0 111 7
1 1110 14
2 11100 28
As shown in the table, shifting the binary number to the left by one place
multiplies the decimal value by 2. Shifting by two places multiplies the
decimal value by 4, and so on.
The following table illustrates the effect of shifting a binary number to the
right:
0 101100 44
1 10110 22
2 1011 11
As shown in the table, shifting the binary number to the right by one place
divides the decimal value by 2. Shifting by two places divides the decimal
value by 4, and so on.
Binary Shifting and Registers
A register is a component in the CPU that stores binary numbers. The
number of bits that a register can store is limited, which can cause bits to
be lost when shifting binary numbers.
The following are the key points to note about binary shifting and registers:
● Shifting a binary number to the left can cause bits to be lost at the
most significant end.
● Shifting a binary number to the right can cause bits to be lost at the
least significant end.
● The number of bits that a register can store is limited, which can
cause overflow errors when shifting binary numbers.
Two's Complement
Two's complement is a number system that represents negative numbers
in binary. The key points to note about two's complement are:
● If the leading bit is 0, the number is positive.
● If the leading bit is 1, the number is negative.
● There are four steps to convert a negative decimal number to two's
complement:
1. Convert the decimal number to positive.
2. Write the positive number in binary form.
3. Invert each binary digit.
4. Add 1 to the inverted binary number.
Computers can receive data in various formats, including text, images, and
sound. Since computers only understand binary, these data types must be
encoded into binary.
Text Encoding
Every character inputted into a computer is represented by a binary code.
Computers use a common set of characters that are recognized by a
variety of systems. The method used to map binary to characters is called
character sets.
Sound Encoding
To process sound, an analog signal is converted into a digital sound. Sound
is captured (e.g., by a microphone), and software converts it into digital
data (0s and 1s). The voice recorded is called a sample.
Steps to produce a clip:
1. The amplitude (loudness) of the sound is determined at set intervals.
2. Each sample of the sound wave is encoded as a series of binary
digits.
Key terms:
Sampling Resolution: The number of bits used to represent sound
amplitude in digital sound recording (also known as bit depth).
Increasing the number of possible values increases the accuracy of the
sample sound but also increases the number of bits used.
Sample Rate: The number of sound samples taken per second, measured
in Hertz (Hz), where 1 Hz means 1 sample per second.
Pros and cons of using a higher sampling rate or larger resolution:
Image Encoding
Pixel Representation
Color Depth
Color depth is the number of bits used to represent each color in a pixel.
● Two bits per pixel allows for
● 22=4
● 2
● 2
● =4 colors.
● Three bits per pixel allows for
● 23=8
● 2
● 3
● =8 colors.
Modern computers often use a 24-bit color depth, producing over 16 million
colors.
Image Resolution
Image resolution is the number of pixels that make up an image.
An image with higher resolution has more pixels and appears clearer.
Basic Terminology
● Bit: The basic unit of computing memory and storage, with a value of
0 or 1.
● Byte: The smallest unit of memory in a computer, equivalent to 8 bits.
● Nibble: Half a byte, or 4 bits.
Steps:
Data Compression
Data compression is reducing the file size while retaining essential
information. It is similar to using a "zip" function on your computer.
Algorith
m Details
Run-Length Encoding
For example, consider a file where each digit is represented by a single byte
(8 bits). If we have a sequence of identical digits, such as "12345678,"
instead of storing each digit as a separate byte, run-length encoding would
store the digit and the number of times it repeats.