Notes Chapter 1 Data Representation
Notes Chapter 1 Data Representation
Digital Data / discrete : Data that are electromagnetically stored in the form of discrete digits
with two values using binary digits 0,1 .
Computers understand only digital data (binary) , so any data must be converted to
binary (digital) to be save and processed by the computers .
Number systems
Denary /decimal system :
1 * 10 3 + 4 * 10 2 + 7 * 10 1 + 8* 10 0 =
1 * 2 7 + 0 * 2 6 + 1 * 2 5 + 0 * 2 4 + 1 * 2 3 + 1 * 2 2 + 0 * 2 1 + 1* 20 =
1*128 + 0*64 + 1 * 32 + 0 * 16 + 1 * 8 + 1 *4 + 0 * 2 + 1*1 =
128 + 0 + 32 + 0 + 8 + 4 + 0 + 1 = 173
128 + 32 + 8 + 4 + 1 = 173
Converting from binary to denary (method1):
It is fairly straightforward to change a binary number into a denary number.
How :
Each time a 1 appears in a column, the column value is added to the total. The 0 values are simply ignored.
For example, the binary number 1 1 1 0 1 1 1 0. is:
128 64 32 16 8 4 2 1
1 1 1 0 1 1 1 0 128 + 64 + 32 + 8 + 4 + 2 = 238 (denary)
Method 1
Consider the conversion of the denary number, 107, into binary.
This method involves placing 1s in the appropriate position so that the total equals to 107 :
Steps :
1. Write the place values for the 8 bits . 1. 107 < 128 The value 0f 8th bit will be 0
2. 107 > 64 the value of the 7th bit will be 1
128 64 32 16 8 4 2 1 3. The remaining number is 107- 64 = 43
4. 43> 32 the value of the 6th bit will be 1
__ __ __ __ __ __ __ __ 5. The remaining number 43 - 32 = 11
6. 11< 16. the value of the 5th bit will be 0
7. 11 > 8 the value of the 4th bit will be 1
8. The remaining number 11- 8= 3
9. 3< 4 the value of the 3rd bit will be 0
10. 3> 2 the value of the 2nd bit will be 1
11. The remaining number 3 - 2 = 1
12. 1 = 1 the value of the 1st bit of 1 is 1
Convert from denary to binary (method2):
Steps :
1. This method involves successive division by 2.
2. The remainders are then read from BOTTOM to TOP to give the binary value.
3. Again using 107, we get:
The hexadecimal system
The hexadecimal system
• Hexadecimal system can be used by humans ,but computer can’t process it ,so the numbers must be
converted to binary .
• Hexadecimal(sometimes referred to as simply ‘hex’) is a base 16 system.
• Therefore needs to use 16 different ‘values’ to represent each digit.
• Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters
A to F are used to represent each hexadecimal (hex) digit:
(A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.)
• Using the same method as denary and binary, this gives the headings of
160, 161, 162, 163 and so on.
The typical headings for a hexadecimal
number with five digits would be:
Convert Hex to Binary
Converting from hexadecimal to binary is also very straightforward.
Using the data in simply take each hexadecimal digit and write down the 4-bit code which
corresponds to the digit.
Example : 4 5 A
find the 4-bit code for each digit:
4 5 A
0100 0101 1010
Put the groups together to form the binary number:
010001011010
Example BF08
Again just use :
B F 0 8
1011 1111 0000 1000
Then put all the digits together:
1011111100001000
Convert Binary to Hex :
Steps :
• Starting from the right
• split the binary number into groups of 4 bits.
• If the last group has less than 4 bits, then simply fill in with 0s from the left.
• Take each group of 4 bits and convert it into the equivalent hexadecimal digit.
Example 1 : 1 0 1 1 1 1 1 0 0 0 0 1
First split this up into groups of 4 bits and find the equivalent hexadecimal digits:
1011 1110 0001
B (11) E(14) 1
Example 2
10000111111101
First split this up into groups of 4 bits:
10000111111101
The left group only contains 2 bits, so add in two 0s:
0010 0001 1111 1101
the equivalent hexadecimal digits: 2 1 F(15) D(13)
Converting from hexadecimal to denary
Steps :
• First multiply each digit by its value:
• Add the totals together:
Example : 4 5 A
Method2
This method involves successive division by 16. The remainders are then read from
BOTTOM to TOP to give the hexadecimal value. Again using 2004, we get:
Use of the hexadecimal system
Uses hexadecimal numbers are used in computer science:
1. Defining color code in HTML : HTML code is often used to represent colours of text on the computer screen. The
different intensity of the three primary colours (red, green and blue) RGB is determined by its hexadecimal value. For
example:#RRGGBB
• #FFFFFF represents colour white
• #000000 represents colour black #222222 represents lighter black
• #FF00 00 represents colour red
6. Memory dump
7. Error messages
8. Location in memory
Use of the hexadecimal system
Why hexadecimal is used to represent binary number?
• easier for programmers to read and understand.
• easier to find errors.
• conversion to binary easier than denary to binary.
• more can be displayed on a screen for addresses etc. // smaller display screens can be used.
• faster than binary for entering numbers.
Binary manipulation and negative numbers
Binary addition:
Addition is done exactly like adding decimal numbers, you have only two digits (0 and 1).
1 1 1 1
Example 2 : 1010110 + 110100 = 10001010:
0 1 0 1 0 1 1 0
+ 0 0 1 1 0 1 0 0
1 0 0 0 1 0 1 0
Binary manipulation and negative numbers
Binary addition: Overflow error
Explain what is meant by an overflow error or overflow condition.
This occurs when a calculation produces a result that is greater than that which a given storage location can store or
represent.
Every computer has a well-defined range of values that it can represent 8 bits, or 16 bits …….
If during execution of a program it arrives at a number outside this range it will experience an overflow error.
The maximum number that can be represented using 8bits range will 255.
A computer or a device has a predefined limit that it can represent or store, for example 16-bit
• An overflow error occurs when a value outside this limit should be returned.
• Overflow will occur when 8 bits are expected to represent a number greater than 255.
1 1 1
• Example perform two logical shift to the right on the binary number 11101100
Use two’s complement to represent negative 8-bit binary integers
In decimal, we use a minus sign to indicate a negative number. But the CPU and memory just know 1's and 0’s.
Two's complement is the way every computer I know of chooses to represent integers.
Example :
Using h 8 bit numbers
find how -28 would be expressed in two's complement notation.
A character set is a complete set of the characters and their number codes that can be recognized and represented by a
computer system, each character and symbol has unique value .
Why Unicode?
Adv . Unicode represents far more characters than ASCII (different alphabets and symbols such as emojis ).
Disadv. while Unicode supports a larger range of characters , and each character is encoded using more bits,
it also takes up a lot more space than ASCII.
How do computers represent images
• A pixel is the smallest unit of a digital image or graphic that can be displayed and represented on a digital display device.
• Image resolution: refers to how many pixels are displayed per inch of an image, It is defined as width by height, or W x
H, where W is the number of horizontal pixels and H is the number of vertical pixels.
Ex : An HD display has a resolution of 1920(wide) x 1080(high) pixels.
• Color depth, also known as bit depth or pixel depth, refers to the number of bits per pixel on a computer monitor and
used to represent a specific color. The greater number of bits per pixel, the greater range of colors to be represented .
• A color image is typically composed of red, green, and blue pixels to create color. Each of these colors is handled by your
computer and monitor as a “channel”.
8 bit color depth means : Having 8bit RGB means that you have 8 bits for each color channel (Red, Green, and Blue),
will have a total of 24-bits per pixel (8 for red, 8 for green, and 8 for blue).
A 16-bit RGB would have 48-bits per pixel((16 for red, 16 for green, and 16 for blue)
The higher the color depth and higher resolution the better image quality , but also higher file size
• Image files usually also contain metadata. Metadata means 'data about data' and provides information about the image.
The information includes:
file format - eg JPEG, GIF or PNG ,dimensions, resolution,colour depth…………
How do computers represent images
Explain how the captured images are converted to digital photo files.
The red line is the wave that represents the audio data we are attempting to store.
Notice that there are 16 possible values that we can assign to the wave (from 0 through to 15).
These 16 values can be represented in 4 bits (since 4 bits allows us to store 16 unique values),
so we say that the data we are storing would have a resolution of 4-bits.
If we were to then reproduce the wave, it would end up looking like the green line on the image
This wave, would thus be stored using the following (decimal) values:
8, 9, 11, 13, 14, 15, 15, 15, 14, 13, 12, 10, 8, 7, 5, 3, 2, 1, 0, 0, 0, 1, 2, 4, 6, 7 Or, in binary representation:
1000, 1001, 1011, 1101, 1110, 1111, 1111, 1111, 1110, 1101, 1100, 1010,
1000, 0111, 0101, 0011, 0010, 0001, 0000, 0000, 0000, 0001, 0010, 0100,
0110, 0111
The higher the sample rate and higher sample resolution the higher
Sound quality , but also higher file size
Measuring Data Storage
Bit : is a smallest unit of data, which holds either 1 or 0 (or on/off).
Nibble : is a sequence of 4 bits
Byte : A byte is a sequence of 8 bits.
• Repeated words (are identified) , and are indexed/put into a table and are replaced with their index .
• their positions , and the number of times the word/pattern appears are stored (in the table) .
Compress sound files
File Formats : MPEG-3 (MP3) and MPEG-4 (MP4)
How to produce MP3:
• Using file compression algorithms which the original music file will be reduced by 90 per cent whilst still retaining
most of the music quality.
• Using PERCEPTUAL MUSIC SHAPING algorithm which :
• Removes sounds (unnecessary data from the file )that the human ear can’t hear properly.
• If two sounds are played at the same time, only the louder one can be heard by the human ear, so the softer
sound is eliminated.
• This means that certain parts of the music can be removed permanently without affecting the quality too
much.
• This means that the original file can’t be put back together again.
• This Reduces sample rate and resolution
• MP3 files use what is known as a LOSSY FILE COMPRESSION.
• the quality of MP3 files can be different since it depends on the sample resolution
Compress image files
File format : Joint Photographic Experts Group (jpeg) files
Image formats : - Raw bitmap formats such as TIFF and BMP are the highest image quality and highest file size
because they are not in a compressed format.
- jpeg, less file size because it is compressed format
Lossless image compression : A similar process of text compression can be applied to an image with lossless called run length
encoding , group together repeating pixels and store how many times occur (figure 1.6 )