mushtaq chapter 1 information representation sir

21
@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq anps@hotmail.com https://sirmushtaq.com/ Chapter 1 Information Representation CS O/A Level by Sir Mushtaq

Upload: others

Post on 14-Feb-2022

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Chapter 1 Information Representation

CS O/A Le

vel b

y Sir M

ushta

q

Page 2: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

1.1 Information representation

.1 Number Representation

Binary Number System:

Binary is a base-2 number system, this means that there are two numbers that you can write for each digit 0, 1. With these two numbers we should be able to write (or make an approximation) of all the numbers that we

could write in denary. Because of their digital nature, a computer's electronics can easily manipulate numbers

stored in binary by treating 1 as "on" and 0 as "off."

Exercise: Binary

Convert the binary numbers into denary (00001100)2

Answer :

128 64 32 16 8 4 2 1

0 0 0 0 1 1 0 0

8+4 = (12)10

Convert the following binary numbers into denary

(01011001)2

CS O/A Le

vel b

y Sir M

ushta

q

Page 3: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Bit patterns in a computer:

The language that a computer understands is very simple, so simple that it only has 2 different numbers: 1 and 0. This is called Binary. Everything you see on a computer, images, sounds, games, text, videos, spreadsheets,websites etc. Whatever it is, it will be stored as a string of ones and zeroes.

What is a bit? A bit is the smallest unit in digital representation of information. A bit has only two values, ON and OFF where ON is represented by 1 and OFF by 0. In terms of electrical signals a 1 (ON) is normally a 5 volt signal and a 0 (OFF) is a 0 volt signal.

Bit

1

What is a nibble?

A group of 4 bits are referred to as a nibble.

Nibble

1 0 0 1

What is a byte?

In the world of computers and microcontrollers, 8 bits are considered to be a standard group. It is called

a byte. Microcontrollers are normally byte oriented and data and instructions normally use bytes. A Byte can

be broken down into two nibbles.

Byte

1 0 0 1 0 1 1 1

What is a word?

Going bigger, a group of bytes is known as a word. A word normally consists of two and sometimes more

bytes belonging together.

Word

1 1 0 1 0 1 1 0 0 0 1 1 0 1 1 1

Hexadecimal

You may notice from the table that one hexadecimal digit can represent exactly 4 binary bits. Hexadecimal is useful to us as a shorthand way of writing binary, and makes it easier to work with long binary numbers.

Hexadecimal is a base-16 number system which means we will have 16 different numbers to represent our digits. The only problem being that we run out of numbers after 9, and knowing that 10 is counted as two digits we need to use letters instead:

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

We can do exactly the same thing as we did for denary and binary, and write out our table.

CS O/A Le

vel b

y Sir M

ushta

q

Page 4: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

1.1 Information representation

1.1.1 Number Representation 16^5 16^4 16^3 16^2 16^1 16^0

1 048 576 65536 4096 256 16 1

0 0 3 4 A F

So now all we need to do is to add the columns containing values together, but remember that A = 10, B =

11, C = 12, D = 13, E = 14, F = 15.

3*4096 + 4*256 + (A)10*16 + (F)15*1 = (13487)16

You might be wondering why we would want to use hexadecimal when we have binary and denary, and

when computer store and calculate everything in binary. The answer is that it is entirely for human ease.

Error messages are written using hex to make it easier for us to remember and record them

following example: CS O/A Le

vel b

y Sir M

ushta

q

Page 5: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

1.1 Information representation

1.1.1 Number Representation

Exercise: Hexadecimal

Convert the following Hex numbers into decimal/denary:

>>A1

Answer :

16 1

A 1

16 * 10 + 1 * 1 = (161)10

Convert the following Hex numbers into decimal/denary:

>>FF

Answer :

16 1

F F

16 * 15 + 1 * 15 = (255)10

Convert the following Hex numbers into decimal/denary:

>>0D

Answer :

16 1

0 D

16 * 0 + 1 * 13 = (13)10 CS O/A Le

vel b

y Sir M

ushta

q

Page 6: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Decimal prefix: A prefix to define the magnitude of a value. Examples are kilo, mega, giga and tera representing factors of 103, 106, 109 and 1012 respectively.

Decimal prefix name Symbol used Factor applied to the valuekilo k 103

mega M 106

giga G 109

tera T 1012

Binary prefix: A prefix to define the magnitude of a value. Examples are kibi, mebi, gibi and tebi representing factors of 210, 220, 230 and 240 respectively.

Binary prefix name Symbol used Factor applied to the valuekibi Ki 210

mebi Mi 220

gibi Gi 230

tebi Ti 240

CS O/A Le

vel b

y Sir M

ushta

q

Page 7: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Positive & negative Integers

Nearly all computers work purely in binary. That means that they only use ones and zeros, and there's no - or + symbol that the computer can use. The computer must represent negative numbers in a different way.

We can represent a negative number in binary by making the most significant bit (MSB) a sign bit, which will

tell us whether the number is positive or negative. The column headings for an 8 bit number will look like

this:

-128 64 32 16 8 4 2 1

MSB LSB

1 0 1 1 1 1 0 1

Here, the most significant bit is negative, and the other bits are positive. You start with -128, and add the other

bits as normal. The example above is -67 in denary because: (-128 + 32 + 16 + 8 + 4 + 1 = -67).

-1 in binary is: 11111111. (-128 + 127)

Note that you only use the most significant bit as a sign bit if the number is specified as signed. If the number

is unsigned, then the msb is positive regardless of whether it is a one or not.

Two’s Complement:

The MSB stays as a number, but is made negative. This means that the column headings are

-128 64 32 16 8 4 2 1

+117 does not need to use the MSB, so it stays as 01110101.

-117 = -128 + 11

= -128 + (8 + 2 + 1) fitting these in the columns give 10001011

CS O/A Le

vel b

y Sir M

ushta

q

Page 8: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

1.1.1 Number Representation

F o u r <spc> a n d <spc> s e v e n

70 111 117 114 32 97 110 100 32 115 101 118 101 110

ASCII

ASCII stands for American Standard Code for Information Interchange.

There are 128 standard ASCII codes, each of which can be represented

by a 7 digit binary number from 000000 through to 111111

The letter 'A' is represented by the code: 01000001

The letter 'B' is represented by the code: 01000010

By looking in the ASCII table, you can see a one-to-one correspondence between each character and the

ASCII code used. 32 is the ASCII code for a space. We could expand these decimal numbers out to binary

numbers (so 32 = 00100000)

The first 32 values (0 through 31) are codes for things like carriage return and line feed. The space character

is the 33rd value, followed by punctuation, digits, uppercase characters and lowercase characters. To see all

127 values try Google “ASCII codes”.

CS O/A Le

vel b

y Sir M

ushta

q

Page 9: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

UNICODE:

The aim of unicode is to represent any text in code form,this includes all languages in the world.how ever

unicode is designed so that once the coding set has been defined it is never changed.The first 128 characters

in unicode are ASCII code.A character code is referred to as a 'code point' in unicode.

An example is U+0041 which is the code point character A .

Notes: All the characters that a system can recognise are called its character set.

A problem arises when the computer retrieves a piece of data from its memory. Imagine that the data is

01000001. Is this the number 65, or is it A?

They are both stored in the same way, so how can it tell the difference?

The answer is that characters and numbers are stored in different parts of the memory, so it knows which one

it is by knowing whereabouts it was stored.

Disadvantages of ASCII codes

• Only 128 / 256 characters can be represented

• Uses values 0 to 127 (or 255 if extended form) / one byte

• Many characters used in other languages cannot be represented

•InextendedASCIIthecharactersfrom128to255maybecoded

differently in different systems

(ii) Any Advantages of UNICODE

• Uses 16, 24 or 32 bits / two, three or four bytes

• Unicode is designed to be a superset of ASCII

• Designed so that most characters (in other languages) can be represented

Binary Coded Decimal (BCD):

BCD use a nibble(group of four bits) to represent a single digit number.The digits are coded as the binary values from 0000 to 1001. The remaining codes 1010 to 1111 do not have any meaning.

So 398602 = 001110011000011000000010 (in BCD)

Note: For BCD arithmatics ,please refere to page 13 of your book.

Application

There are a number of applications where BCD can be used. The obvious type of application is where denary digits are to be displayed, for instance on the screen of a calculator or in a digital time display.

Packed BCD: when two BCD nibbles are stored in one byte

for example, the denary digits 8503 could be represented by either of the codes below

Two BCD digits per byte

One BCD digit per byte 00001000 00000101 00000000 00000011

10000101 00000011

CS O/A Le

vel b

y Sir M

ushta

q

Page 10: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Binary arithmetic

Recall the rule of denary numbers addition,Two rules apply. The first rule is that the process is carried out starting with addition of the two least significant digits and then working right to left. The second rule is that if an addition produces a value greater than 9 there is a carry of 1. For example in the addition of 48 to 54, the first step is adding 8 to 4 to get 2 with a carry of 1. Then 5 is added to 4 plus the carried 1 to give 0 with carry 1. The rules produce 102 for the sum which is the correct answer.

For binary addition, starting at the least significant position still applies. The rules for the addition of binary digits are:

• 0 + 0 = 0• 0 + 1 = 1• 1 + 1 = 0 with a carry of 1• 1 + 1 + 0 = 0 with a carry of 1• 1 + 1 + 1 = 1 with a carry of 1The last two rules are used when a carried 1 is included in the addition of two digits.

The steps followed from right to left are:

• 1 + 0 = 1 with no carry• 1 + 1 = 0 with carry 1• 0 + 1 + carried 1 = 0 with carry 1• 1 + 1 + carried 1 = 1 with carry 1

1 0 1 11 1 1 0

1 1 0 0 1

CS O/A Le

vel b

y Sir M

ushta

q

Page 11: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Bitmap file header A bitmap file has to store the pixel data but the file must also have a header that defines the resolution of the image, the coding scheme for the pixel color and that it is not damaged.

Bitmap image Bitmap (or raster) images are stored as a series of tiny dots called pixels. Each pixel is actually a very small square that is assigned a color, and then arranged in a pattern to form the image. When you zoom in on a bitmap image you can see the individual pixels that make up that image. Bitmap graphics can be edited by erasing or changing the color of individual pixels using an image processing softwares.

The resolution of the image can be represented as the product of number of pixels per row times the number of rows.

It is important to distinguish between the resolution of a stored image and the resolution of a monitor screen which is used to display the image.

The bitmap image is scalable but number of pixels in the image doesn’t change however if the image is magnified too far the quality of display will deteriorate and individual pixels can be seen.

What is the difference between bitmap and vector images? Unlike bitmaps, vector images are not based on pixel patterns, but instead use mathematical formulas to draw lines and curves that can be combined to create an image from geometric objects such as circles and polygons. Vector images are edited by manipulating the lines and curves that make up the image

Vector images have some important advantages over bitmap images. Vector images tend to be smaller than bitmap images. That’s because a bitmap image has to store color information for each individual pixel that forms the image. A vector image just has to store the mathematical formulas that make up the image, which take up less space.

Vector images are also more scalable than bitmap images. When a bitmap image is scaled up you begin to see the individual pixels that make up the image. This is most noticeable in the edges of the image. There are ways of making these jagged

Images

CS O/A Le

vel b

y Sir M

ushta

q

Page 12: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

edges less noticeable but this often results in making the image blurry as well. When a vector image is scaled up, the image is redrawn using the mathematical formula. The resulting image is just as smooth as the original.

Unfortunately, vector formats are not well supported on the web. The two most popular image formats used on the Web, GIF and JPEG are bitmap formats. Most vector images must first be converted into bitmaps images (or rasterized) before they can be used on the Web. An exception is the SWF format used to create animations using Macromedia’s Flash animation software.

Bitmap formats are best for images that need to have a wide range of color gradations, such as most photographs. Vector formats, on the other hand, are better for images that consist of a few areas of solid color. Examples of images that are well suited for the vector format include logos and type.

Vector graphics is the use of geometrical primitives suchas points, lines, curves, and shapes or polygons—all of which are based on mathematical expressions—to represent images in computer graphics.

A vector graphics file contains a drawing list which contains command for each objectinclude in the image.

Each command has the properties of the objecte.g. for a circle, the position of the Centre and its radius.

The dimensions of the objects are defined relative to an imaginary drawing canvas soimage is scalable.

Whenever the image is to be displayed the file is read, the appropriate calculations aremade and objects are drawn to suitable scale.

If the user wants to redraw the image at a larger scale the file is read again and anotherset of calculations are made before the image is displayed.

CS O/A Le

vel b

y Sir M

ushta

q

Page 13: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

4. Bitmaps Vs Vectors

A common exam question is to ask you to compare the differences between vector grnphics and

bitmap graphi1cs.

Use the information below to help you answer this type of questim1.

Use less processing power than vectors Use mofe processing power than bitmaps

Made up from pixels Made LUp from lines equations and calcLUlations

lndividLUal elements cannot be groLUped lndividLUal elements can be groLUped

Images are less precise than vectors Images are more precise ttian bitmaps

Take up more memory ttian vectors Take LUp less memory than bitmaps

Take up more storage space ttian vectors Take up less storage space than bitmaps

CS O/A Le

vel b

y Sir M

ushta

q

Page 14: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Estimating file size of bitmapped image of different resolutions

File size of a black white image

A black and white image has two dimensions that need to be considered the number of

pixels in the horizontal plane multiplied number of pixels along the vertical axis. Note

that a black and white image is not grey scale.

Example

The formula is:

File size = horizontal pixels × vertical pixels × bit depth

------------------------------------------- 8(to convert to bytes) × 1024 (kilobytes)

This image has the properties of 208 pixels wide by 182 pixels high. The file size in bits

can then be worked out by multiplying horizontal pixels by vertical pixels.

file size = 208 × 182 x 1

8 × 1024

= 37856

------ 8192 = 4.62 KB

CS O/A Le

vel b

y Sir M

ushta

q

Page 15: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Bit Depth

(Bits Per Pixel)

Number of

Colours

or Tones

Where do # of

Colours Come

From?

1 2 21=2

2 4 22=4

3 8 23=8

4 16 24=16

6 64 26=64

8 256 28=256

This grey scale image has 3 dimensions. Lets examine the properties of this image.

Remember that because this image is a gif the actual file size will be different to the

result in the formula.

The image is 200 pixels horizontal by 200 pixels vertical. Now we need to know the bit

depth. The bit depth of this image is 8.

File size = 200 × 200 × 8

----------------- 8 × 1024

= 320000

---------- 8192

=39 KB CS O/A Le

vel b

y Sir M

ushta

q

Page 16: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Activity 2

1. Find an uncompressed image. Right click on the thumbnail of the image and click on

properties. Now click the summary tab. You now can find all the details you need to workout the file size of an image.

Calculating video size

The file size of an animation is simply a process of multiplying the number of frames by the

image size of each image.

Image courtesy of Bettscomputers.com

CS O/A Le

vel b

y Sir M

ushta

q

Page 17: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Sound To store a sound or to send it electronically, the original sound needs to be converted from analogue to binary code. a sound encoder is used which has two components.

Band limiting factor means remove high frequency components which cannot be detected by human ear but can cause problem for coding.

Second component is ADC analogue to digital converter.

Sampling Amplitude of sound wave taken at different points in time Measurement of value of analogue signal at regular time intervals/a point in time

Sampling resolution Specified by the number of bits used to store/record each sample

It is also known as bit depth

The higher the sampling resolution, the smaller the quantization error

A higher sampling resolution results in less distortion of the sound

Usually 8 bit, 16 bit, 24 bit or 32 bit

Sampling rate How often the samples are taken i.e. how many values per second

Features of sound editing software Once a digital data of sound has been stored in a file it can be manipulated using sound editing software It

can have the following features

Edit start time, stop time and duration of any sound/timeline

Extract/delete/save part of a clip

Frequency, amplitude, pitch alteration

Fade in/out of a clip

Mix/merge multiple sound sources/tracks Combine different

sources at various volume levels Use of filters

Conversion between different audio file formats

CS O/A Le

vel b

y Sir M

ushta

q

Page 18: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

The other decision concerns the choice of the sampling rate, which is the number of samples taken per

second. This should be in accordance with Nyquist's theorem which states that sampling must be done

at a frequency at least twice the highest frequency in the sample.

CS O/A Le

vel b

y Sir M

ushta

q

Page 19: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

2. Five minutes of speech is sampled at 8000 samples per second, and each sample is encoded into 16 bits (2

bytes). How big will the resulting speech file be?

Answer

1. 5 minutes = 300 seconds. So there are 300 × 40 000 samples. Each sample occupies 2 bytes, making a file

size of 300 × 40 000 × 2 bytes, which is 24 000 000 bytes – some 24 megabytes!

2. A sampling rate of 8000 per second will generate a fifth as many samples as a rate of 40 000 per second. So

the speech file will ‘only’ be 4 800 000 bytes.

1. Five minutes of music is sampled at 40 000 samples per second, and each sample is encoded into 16 bits (2

Activity 21 (Self assessment)

bytes). How big will the resulting music file be?

CS O/A Le

vel b

y Sir M

ushta

q

Page 20: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Data compression is a process by which the file size is reduced by re-

encoding the file data to use fewer bits of storage than the original file. The original

file can then be recreated from the compressed representation using a reverse

process called decompression. There are several different algorithms and

implementations that allow you to compress your files, some of which perform

better than others for certain kinds of file types.

Image compression

CS O/A Le

vel b

y Sir M

ushta

q

Page 21: Mushtaq Chapter 1 Information Representation Sir

@sirmushtaq 03125275281 www.youtube.com/c/MuhammadMushtaq [email protected] https://sirmushtaq.com/

Lossless compression

Lossless compressions ensure that you can recreate the original file bit for bit in its entirety, which means there is no data loss during the compression and decompression. This type of compression is usually a must if you are compressing text files, data files or certain proprietary formats.

Run-Length encoding

RLE works by reducing the physical size of a repeating string of characters. This repeating string, called a run, is typically encoded into two bytes. Uncompressed, a character run of 15 A characters would normally require 15 bytes to store: AAAAAAAAAAAAAAA The same string after RLE encoding would require only two bytes: 15A The 15A code generated to represent the character string is called an RLE packet. Here, the first byte, 15, is the run count and contains the number of repetitions. The second byte, A, is the run value and contains the actual repeated value in the run.

AAAAAAbbbXXXXXt Using run-length encoding this could be compressed into four 2-byte packets: 6A3b5X1t Thus, after run-length encoding, the 15-byte string would require only eight bytes of data to represent the string, as opposed to the original 15 bytes. In this case, run-length encoding yielded a compression ratio of almost 2 to 1.

Huffman coding. The procedure used to carry out the compression is quite detailed but the principle is straightforward. Instead of having each character coded in one byte an analysis is carried out to find the most often used characters. These are then given shorter codes. The original stream of bytes becomes a bit stream. A possible set of codes if a text contained only eight different letters is shown in Table

Lossy compression

This type of compression is done mainly on media files such as image, audio and video files. Depending on the usage of the files, a certain amount of loss in quality might be acceptable to save space and resources. More often than not the loss in quality is usually not detectable for all practical purposes.

CS O/A Le

vel b

y Sir M

ushta

q