0% found this document useful (0 votes)
2 views

Data Representation

The document covers data representation in computer science, focusing on number systems such as binary, denary, and hexadecimal, along with conversion methods between them. It also explains binary operations, including addition, multiplication, and overflow conditions, as well as the two's complement system for representing negative numbers. Additionally, the document discusses how various data types, including text, sound, and images, are encoded in binary and the implications of sampling rates and resolutions on data size.

Uploaded by

spritefanta2009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Data Representation

The document covers data representation in computer science, focusing on number systems such as binary, denary, and hexadecimal, along with conversion methods between them. It also explains binary operations, including addition, multiplication, and overflow conditions, as well as the two's complement system for representing negative numbers. Additionally, the document discusses how various data types, including text, sound, and images, are encoded in binary and the implications of sampling rates and resolutions on data size.

Uploaded by

spritefanta2009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Computer science Notes 0478 ​


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.

Binary is the only language a computer can understand.


This is because computers contain millions of tiny switches that can be
either on or off.

●​ 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.

Binary to Denary Conversion

To convert a binary number to a denary value, multiply each digit by its


place value. In the binary system, the place values are powers of 2, starting
from the rightmost digit:
... 2^3, 2^2, 2^1, 2^0
... 8, 4, 2, 1
For the binary number 1011, the conversion is as follows:
\1 \times 8 + 0 \times 4 + 1 \times 2 + 1 \times 1 = 11$.
Thus, the denary equivalent of the binary number 1011 is 11.

Denary to Binary Conversion


To convert a denary value to binary, repeatedly divide the denary number by
2 and record the remainders. The binary number is then constructed by
reading the remainders from bottom to top.

For example, to convert 39 to binary:


1.​ $39 div 2 = 19$ with a remainder of 1
2.​ $19 div 2 = 9$ with a remainder of 1
3.​ $9 div 2 = 4$ with a remainder of 1
4.​ $4 div 2 = 2$ with a remainder of 0
5.​ $2 div 2 = 1$ with a remainder of 0
6.​ $1 div 2 = 0$ with a remainder of 1

Reading the remainders from bottom to top gives us 100111.


Therefore, the binary equivalent of the denary number 39 is 100111.

Hexadecimal System

The hexadecimal system is a base-16 system.

System Base Values

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.

Conversion of Binary to Hexadecimal


To convert a binary number to hexadecimal:
1.​ Split the binary number into chunks of four digits, starting from the
right.
2.​ Map each chunk to its respective hexadecimal value using the table
provided.
3.​ Concatenate the hexadecimal values.

Example:

Convert the binary number 10111001 to hexadecimal.


1.​ Split into chunks of four: 1011 1001.
2.​ Map each chunk to its hexadecimal value:
●​ 1011 = B
●​ 1001 = 9
●​
Therefore, the hexadecimal equivalent of the binary number 10111001 is
B9.

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:

1.​ Split into chunks: 0010 1111 1101.


2.​ Map each chunk:
●​ 0010 = 2
●​ 1111 = F
●​ 1101 = D
Therefore, the hexadecimal equivalent of the binary number 1011111101 is
2FD.
Conversion of Hexadecimal to Binary
To convert a hexadecimal value back to binary, map each hexadecimal digit
to its respective four-digit binary value and concatenate the binary values.

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.

Example: Convert 2004 to hexadecimal.

1.​ Divide 2004 by 16:


●​ Quotient: 125
●​ Remainder: 4
2.​ Divide 125 by 16:
●​ Quotient: 7
●​ Remainder: 13 (which is 'D' in hexadecimal)
3.​ Divide 7 by 16:
●​ Quotient: 0
●​ Remainder: 7
Reading the remainders from bottom to top, we get 7D4.
Therefore, 2004 in denary is equal to 7D4 in hexadecimal.
Hexadecimal to Denary
The method to convert hexadecimal to denary is similar to how we convert
binary to denary.

Multiply the digit value by its place value. The place values in hexadecimal
are powers of 16 (1, 16, 256, etc.).

Example: Convert a hexadecimal number to denary.

–Before doing the basic multiplication, we must remember that in


hexadecimal, the characters A-F represent the values 10-15.
Multiply the place value with the digit's value to obtain the denary
equivalent.

Usages of Hexadecimal System in Computer Science


Hexadecimal is used because it is easier to visualize and more compact
than binary. One hexadecimal digit represents four binary digits, reducing
the length of the data by a quarter.

HEMI Mnemonic
Here's a breakdown of the usages of hexadecimal, summarized by the
mnemonic HEMI:

●​ H - HTML Color Code: Used in website development to specify colors


in hexadecimal format.
●​ E - Error Codes: Tells programmers the location of errors.
●​ M - MAC Address: A unique identifier for devices.
●​ I - IP Address: An address given to a device connected to a network,
represented in hexadecimal.
Binary Addition

Rules of Binary Addition :

●​ 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.

Binary Addition and Overflow


Binary addition is a process where two binary numbers are added together.
The overflow condition occurs when the result of the addition exceeds the
maximum value that can be stored in an 8-bit binary number. This
maximum value is 255, which is represented by eight 1's in binary.
The overflow condition is a situation where the result of a binary operation
exceeds the maximum value that can be stored in a binary number.
When an overflow occurs, the extra bit generated is called the knife bit. This
bit is lost when the result is stored in an 8-bit binary number, resulting in an
overflow error.
Binary Multiplication and Division
Binary multiplication and division are performed using a method called
binary shifting. This involves shifting the binary number to the left or right
to multiply or divide by a power of 2.
The following table illustrates the effect of shifting a binary number to the
left:

Shift Binary Number Decimal Value

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:

Shift Binary Number Decimal Value

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.

The following table illustrates the conversion of a negative decimal number


to two's complement:

Decimal Number Positive Binary Inverted Binary Two's Complement

-67 1000011 0111100 0111101

\When finding the two's complement of a binary number, the following


steps are used:
1.​ Convert the decimal value into positive binary.
2.​ Invert the binary digits (0 becomes 1, and 1 becomes 0).
3.​ Add 1 to the inverted binary number.
For example, converting -67 to two's complement:
1.​ Convert 67 to binary: 01000011
2.​ Invert the digits: 10111100
3.​ Add 1: 10111101

Therefore, the two's complement of -67 is 10111101.​

To convert a two's complement value back to a negative decimal value, you


can use a similar process as converting binary to decimal, but with the
leftmost digit's place value being negative. For example, in an 8-bit two's
complement number, the leftmost bit represents -128.

Representing Data Types

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.

Two common character sets:

●​ ASCII Code: Each letter is represented by a certain binary code (e.g.,


01100001 represents 'a'). The extended ASCII code uses 8 bits,
representing 255 unique characters.
●​ Unicode: Uses 16 bits to represent characters, enabling over 65,000
characters.

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:

Aspect Pros Cons

Larger file size, takes longer to


Sampling Larger dynamic range, better
download, requires greater
Rate sound quality, less distortion
processing power

Sampling Increased accuracy of sound,


Larger file size, increased
Resolutio better representation of
processing requirements
n sound amplitude

Image Encoding

Images are represented in something called a bitmap, which is a map of


bits that forms a picture. A video is just a series of pictures. An image is
made up of a two-dimensional grid, with horizontal and vertical axes. Each
pixel is stored in the computer as a series of binary numbers.

Image Representation in Computers

Computers understand images as a collection of pixels, each represented


by binary values that define its color.

Pixel Representation

Each pixel's color is determined by a binary value.


●​ Black and White Images: If one bit represents a pixel, the image is
black and white (0 or 1).
●​ Multiple Colors: Increasing the number of bits per pixel allows for
more colors.

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.

Cons of High Resolution:


●​ Increased file size.
●​ Longer download times.
●​ Reductions in resolution are possible before quality loss
becomes noticeable.

Measuring Data Size

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.

IEC Base 2 System of Units


To better organize and name the bytes, the IEC base 2 system is used.
●​ 1 kilobyte (KB) =
●​ 210
●​ 2
●​ 10
●​ bytes = 1024 bytes

Converting Bytes to KB: Divide the number of bytes by 1024.


For converting in the opposite direction, multiply instead of dividing.

Calculating Audio File Size


To calculate the size of an audio file, we use the following formula:
File Size=Sample Rate×Sample Resolution×Length of Sample (in seconds)
File Size=Sample Rate×Sample Resolution×Length of Sample (in seconds)
Example 1: Mono Sound

Given a mono sound with the following properties:


●​ Sample Rate
●​ Sampling Resolution
●​ Length of Music

The goal is to find the size of the audio in kilobytes (KB).


Steps:
1.​ Calculate the total number of bits using the formula above.
2.​ Convert bits to bytes by dividing by 8.
3.​ Convert bytes to kilobytes by dividing by 1024.

Example 2: Stereo Sound

Consider a CD with the following properties:


●​ Sample Rate: 44,000 Hz
●​ Sampling Resolution: 16 bits
●​ Stereo Recording (2 channels)
●​ Length: 16 minutes

Steps:

1.​ Convert the length of the recording to seconds:


2.​ 16 minutes×60 seconds/minute=960 seconds
3.​ 16 minutes×60 seconds/minute=960 seconds.
4.​ Calculate the number of bits using the formula above, and multiply by
2 for stereo sound.
5.​ Convert bits to bytes by dividing by 8.
6.​ Convert bytes to megabytes (MB) by dividing by 1,048,576
(1024*1024).
Total Bits=44,000×16×960×2
Total Bits=44,000×16×960×2
MB=1024×1024 Bytes

Data Compression
Data compression is reducing the file size while retaining essential
information. It is similar to using a "zip" function on your computer.

Benefits of Data Compression:


●​ Reduces streaming time.
●​ Decreases the time to upload and download media.
●​ Reduces costs.
●​ Saves storage space.

Types of Data Compression:

1.​ Lossy File Compression:​


Eliminates unnecessary data from the file. The original file cannot be
perfectly reconstructed after compression.
2.​ Lossless File Compression:​
Preserves all original data, allowing the file to be perfectly
reconstructed after compression.

Lossy File Compression Details

Algorith
m Details

Reduces music file size by removing sounds outside the human


MP3
ear range and soft sounds we can't hear.

Reduces video file size by removing certain pixels without


MP4
noticeable differences.
Reduces image file size by reducing color shades that are hard
JPEG
to notice.

Reducing Image Size with Lossy Compression


To reduce the size of an image, one can reduce the image resolution or the
color depth.

Image Size=Image Resolution×Color Depth


Image Size=Image Resolution×Color Depth

Reducing Sound Size with Lossy Compression


To reduce the size of a sound file, one can reduce the sample rate,
sampling resolution, or the length of the audio.
Sound Size=Sample Rate×Sampling Resolution×Time
Sound Size=Sample Rate×Sampling Resolution×Time

Lossless File Compression Details


Once a file is compressed, all data from the original uncompressed file can
be reconstructed.
One algorithm for lossless file compression is Run Length Encoding (RLE).

Run Length Encoding (RLE)


RLE reduces the size of a string of adjacent and identical data. A repeated
string is encoded into two values: the number of repetitions and the data
value.

For example, consider the data:


AAAAABBBBCCDDDDD
Here, we have five A's, four B's, two C's, and five D's concatenated together.
Assuming each character is represented by 8 bits, the file size would be 16
bytes.

Using RLE, we can encode this as:


5A4B2C5D

Instead of using five bytes to represent AAAAA, we use two bytes to


represent 5A.

Run-Length Encoding

Run-length encoding is a data compression technique that reduces file size


by storing the length of consecutive identical data values rather than the
values themselves.

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.

This approach is beneficial when the data contains long sequences of


identical values. In the example provided, representing each digit separately
would require 16 bytes. However, using run-length encoding can reduce the
file size by half without losing any information.
However, run-length encoding is only useful when your data is very identical
to each other.

More advanced and efficient file compression algorithms exist for


computer science.
Topics covered:
●​ Number systems
●​ Text representation
●​ Sound representation
●​ Image representation
●​ File size calculation
●​ Data compression

You might also like