Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
80 views

Notes Chapter 1 Data Representation

Binary and hexadecimal are common number systems used in computing. Binary uses only two digits, 0 and 1, and is used internally by computers to represent data. Hexadecimal uses 16 digits, 0-9 and A-F, and is commonly used by humans to represent things like colors, MAC addresses, and machine code. Data must be converted between its raw form and binary to be processed by computers.

Uploaded by

taaram ishfaq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Notes Chapter 1 Data Representation

Binary and hexadecimal are common number systems used in computing. Binary uses only two digits, 0 and 1, and is used internally by computers to represent data. Hexadecimal uses 16 digits, 0-9 and A-F, and is commonly used by humans to represent things like colors, MAC addresses, and machine code. Data must be converted between its raw form and binary to be processed by computers.

Uploaded by

taaram ishfaq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Data representation

1.1 Binary and hexadecimal system .


What Is a Number System?
Number system is a way to represent numbers.
We are used to using the base-10 (0-9) number system, which is also called decimal/denary .
Other common number systems include base-16 (hexadecimal 0-F), and base-2 (binary 0-1).

What is the importance of binary system in computers?


• Computers use binary because they can only read and store an on or off charge. Zero (0) is
equivalent to off and one (1) is equivalent to on.
• Computers use binary – the digits 0 and 1 – to store data.
The circuits in a computer’s processor are made up of billions of transistors .
• A transistor is a tiny switch that is activated by the electronic signals it receives. The digits 1 and 0 used in
binary reflect the on and off states of a transistor.
• Binary numbers can be considered the very basic representation of a number in an electronic device.
Types of data:
Analogue data / continuous : Analog data is data that is represented in a physical
way, that is processed by humans , everything we can see, hear,smell is continous
stream to our senses .
Sound, videos and images are in analogue form.

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 :

• Base 10 using numbers 0-9 .


• Most of the numbers used internationally are denary numbers .
• Place value of denary goes up in factors of ten : ones , tens , hundreds ,
thousands …………..
ten thousands thousands hundreds Tens ones
* 10 4 * 10 3 * 10 2 * 10 1 * 10 0

Example : the number 1478.

1 * 10 3 + 4 * 10 2 + 7 * 10 1 + 8* 10 0 =

1000 + 400 + 70 + 8 = 1478


Binary system Click her to watch the video
Denary /decimal system :

• Base 2 using numbers 0-1 .


• Used to represent data used by the processors .
• The units for the binary number bit , nibble , byte , ……….
• Place value of Binary goes up in factors of 2 .
128 64 32 16 8 4 2 1
Place value
* 27 * 26 * 25 * 24 * 23 *22 *21 *20
Example 1 0 1 0 1 1 0 1

Example : the number 10101101. convert to denary

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)

Convert the following binary numbers into denary:


a 00110011
b 01111111
c 10011001
d 01110100
e 11111111
f 00001111
g 10001111
h 11110000
i 01110000
j 11101110
Convert from denary to binary (method1):
The first method : is ‘trial and error’.
The second method is more methodical and involves repetitive division.

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

denary number (total ) = 1 1 1 4


Converting from denary to hex:
To convert from denary to hexadecimal is a little more difficult.
As with the conversion from binary to denary, there are two very similar methods that can be used. Again, the first
method is ‘trial and error’ and the second method is more
methodical and involves repetitive division.
Method 1
Consider the conversion of the denary number, 2004, into hexadecimal.
This method involves placing hexadecimal digits in the appropriate position so that the total
equates to 2004:

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

2. MAC address/physical /hardware address :


• A MEDIA ACCESS CONTROL (MAC) ADDRESS refers to a number which uniquely identifies a device on the
internet.
• Physical address/hardware address
• Is a static address .
• The MAC address refers to the network interface card (NIC) which is part of the device given by manufacturer.
• A MAC address is usually made up of 48 bits which are shown as six groups of
hexadecimal digits (although 64-bit addresses are also known):
NN:NN:NN:DD:DD:DD
where the first half (NN – NN – NN) is the identity number of the manufacturer of the device
the second half (DD – DD – DD) is the serial number of the device.
Use of the hexadecimal system
3. Used in assembly language/machine code.

4. ASCII CODE :Each character used on a keyboard has what is known as an


ASCII CODE (AMERICAN STANDARD CODE FOR INFORMATION
INTERCHANGE).
These codes can be represented using hexadecimal values or decimal
values.

ASCII, was designed to represent only basic English characters using


8bits numbers.
Unicode was designed to support characters from all languages around
the world using 16/32 bits numbers . While ASCII only uses
one byte(8bits) to represent each character, Unicode supports up to 4
bytes (32bits) for each character , this means that all characters can be
developed in different alphabets and symbols such as emojis .
Use of the hexadecimal system
5. Web addresses. URL :
• A good example of the use of ASCII codes is the representation of a web address (or
URL, which stands for uniform resource locator) such as www.hodder.co.uk which
becomes (using hexadecimal values):

(Note: the % sign is used to denote that hexadecimal is being used.)

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).

Four rules to remember :

• 0+0 = 0, with no carry,


• 1+0 = 1, with no carry,
• 1+1 = 10 ( means 2). So the result is 0 and carry 1.
• 1+1+1 = 11 ( means 3) . So the result is 1 and carry 1
1
Example 1 : 1011 + 10010 = 11101: 0 0 0 0 1 0 1 1
+ 0 0 0 1 0 0 1 0
0 0 0 1 1 1 0 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

110001 + 11100100 = 100010101: 0 0 1 1 0 0 0 1


Overflow. The carry-out is discarded, and the sum is not correct + 1 1 1 0 0 1 0 0
0 0 0 1 0 1 0 1
1 1 1
1 0 0 1 1 0 1 1
10011011 + 1001010 = 11100101:
+ 0 1 0 0 1 0 1 0
No overflow. Sum is correct. 1 1 1 0 0 1 0 1
Logical binary shift
• Logical shifts can be useful as efficient ways to perform multiplication or division of
unsigned integer by powers of two.
• Shifting left by n bits on an unsigned binary number has the effect of multiplying it by 2 n.
• Shifting right by n bits on an unsigned binary number has the effect of dividing it by
2n (rounding towards 0).

• 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.

To get the two's complement negative notation of an integer:


• Write out the number in binary.
• Invert the digits (change 1 to 0 and 0 to 1)
• Add one to the result.

Example :
Using h 8 bit numbers
find how -28 would be expressed in two's complement notation.

1. Write out 28 in binary form: 00011100


2. Invert the digits. 0 becomes 1, 1 becomes 0: 11100011
3. Add 1: 11100100 → -28 in 8 bit binary
How do computers represent Text
Convert text to binary
When computer converts text to binary to be processed it uses a tool called character set .
All the characters and symbols that can be represented by a computer system.
• Each character and symbol is assigned a unique value.

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 .

The types of character set are :


ASCII Code using 8 bits
Unicode using 16/32 bits

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.

– Image is converted from analogue to digital (using ADC)


– Image is turned into pixels
– Each pixel is given a binary value
– Pixels form a grid (to create the image)
– Each pixel has a colour
– Pixels are stored in sequence (in a file)
– Meta data is stored (to describe the dimensions/resolution of the image) // It stores the dimensions/colour
depth .etc.
– An example of a suitable photo file format e.g. JPEG
How do computers represent sounds
Sampling is a method of converting an analogue audio
signal into a digital signal.
Sampling sound is the process of converting an analogue
sound wave into a digital signal.

Convert from analogue to digital is dependent on two


things:
• Sample rate
• Sample resolution

Sample rate :is how many samples, or measurements, of the


sound are taken each second. The more samples that are taken,
the higher the quality of the audio. Also, the shape of the sound
wave is captured more accurately.

A common audio sample rate for music is 44,100 samples per


second. The unit for the sample rate is hertz (Hz). 44,100 samples
per second is 44,100 hertz or 44.1 kilohertz (kHz).
How do computers represent sounds
Sample resolution : the number of bits per sample

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

If we then count up the number of bits used to store this wave,


we would have 26 values x 4 bits = 104 bits = 13 bytes.

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.

Solve skills 1.3


Lossless and lossy file compression

File compression is a method in which the size of a file is reduced .


WHY benefits :
• To save disk space that the compress file takes up less storage space
• Easier and faster transmission over a network or the Internet:
• upload
• download
• Would not slow website down
• Take less bandwidth for transmitting file over the internet.

Types of file compression:


1. Lossless file compression : text files (emails , text messages ……)
2. Lossy file compression : image and sounds ………
Lossless and lossy file compression
Lossless file compression : file extention : .zip , .rar , ……
• All the data bits from the original file are reconstructed /restored when the file is again uncompressed.(Advantage )
• A (compression) algorithm is used .
• No data is removed in the process .
• Repeated ptterns in text files are identified and are indexed into a table , and the number of times the word/pattern appears is
stored in the table .
• Used with Ex . Text , spreadsheet files , emails,……

Lossy file compression:


• A compression algorithm is used .
• The file compression algorithm eliminates unnecessary bits of data as seen in MP3 and jpeg formats.
• It is impossible to get the original file back once it is compressed. (Disadvantage )
• This is why it is chosen for files where removing certain bits doesn’t detract from the quality.
• Advantages :
• The file size will be smaller than lossless
• Requires less storage space
• Requires less time to transmit
Compress text file using lossless compression
File Formats :Text and number file formats
• Text and numbers can be stored in a number of formats.
• Text is usually stored in an ASCII format .
• It is important that the correct format is chosen if some form of processing is to be done .
• If number files undergo any form of file compression, then it tends to be lossless. Since it very important that none of the
information/data is lost

Text files can also undergo file compression How?


• No data is removed in the process // original file can be restored
• These use complex compression algorithms that work on repeated sections of words :
Ex : The following section shows, in very simple terms, how this could work:
The phrase ‘THIS SECTION SHOWS YOU HOW THIS WOULD WORK’,, ignoring spaces, = 35 CHARACTERS
1 2 3 2 1 3
the compress text : 1 SECTION S2S Y3 2 1 W3LD WORK = 23 CHARATERS SAVE ABOUT 33%
1 for THIS
2 for HOW
3 FOR OU

• 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

How to convert to JPEG FORMAT :


• the size of the file is reduced.
• A compression algorithm is used
• Data will be lost/deleted permanently // original file cannot be recreated
• this reduced file size is reduced quality of the image.
• Reduce the range of colours used / colour depth / bits per pixel
• The human eye is limited in its ability to detect very slight differences in brightness and in color hues.
• Reduce the number of pixels ( image resolution) by removing colors that will not be recognized by human eye

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 )

You might also like