Chapter 1
Chapter 1
In our normal everyday life we use the decimal number system which is a base-10 number
system. The numbers in the decimal number system are called denary numbers. A binary
number system, on the other hand, is a base-2 number system. This system uses only 0s
and 1s to represent letters, numbers and other characters and it is used by modern
computers. Computers make use of electronic circuits which use electricity. Electricity has
two possible states either ON or OFF. Hence, the binary number system is an ideal method
of representing the state of circuits since it uses a combination of zero and one only. The
binary digits 0 and 1 are known as binary bits.
To turn a denary number into a binary number simply put the column headings, start at the left hand
side and follow the steps:
If the column heading is less than the number, put a 1 in the column and then subtract the
column heading from the number. Then start again with the next column on the right.
If the column heading is greater than the number, put a 0 in the column and start again with the
next column on the right.
Note: You will be expected to be able to do this with numbers up to 255, because that is the biggest
number that can be stored in one byte of eight bits.
128 64 32 16 8 4 2 1
128 64 32 16 8 4 2 1
0
64 is less than 117 so put a 1.
128 64 32 16 8 4 2 1
0 1
Take 64 from 117 = 53, and repeat.
1
128 64 32 16 8 4 2 1
0 1 1
Take 32 from 53 = 21, and repeat.
128 64 32 16 8 4 2 1
0 1 1 1 0 1 0 1
So 117 (in denary) = 01110101 (in binary).
To turn a binary number into denary, simply put the column headings above the binary number and
add up all the columns with a 1 in them.
Answer:
128 64 32 16 8 4 2 1
1 0 1 1 0 1 1 0
So 10110110 = 128 + 32 + 16 + 4 + 2 = 182 (in denary).
256 16 1
So 117 (in denary) is 7 lots of 16 (112) plus an extra 5. Fitting this in the columns gives
256 16 1
0 7 5
2
Practice Exercises
1. Convert the following denary numbers into binary.
5, 12, 25, 119, 125
2. Convert the following binary numbers into denary.
10
111
10101
11110
10001111
You could also use the hexadecimal code for red, which is #FF0000.
3
A sample screenshot of Ms Visual Basic interface
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 or NN:NN:NN:DD:DD:DD
where the first half (NN – NN – NN) is the identity number of the manufacturer of the
device and the second half (DD – DD – DD) is the serial number of the device.
4
(c) Assembly Language
Hexadecimal in assembly language coding is used instead of binary to make it much simpler
for humans to write codes.
5
Binary Coded Decimal
Some numbers are not proper numbers because they don’t behave like numbers. A barcode for
chocolate looks like a number, and a barcode for sponge cake looks like a number, but if the
barcodes are added together the result is not the barcode for chocolate cake. The arithmetic does
not give a sensible answer. Values like this that look like numbers but do not behave like them are
often stored in binary coded decimal (BCD). Each digit is simply changed into a four bit binary
number which are then placed after one another in order.
8 = 1000 6 = 0110
0 = 0000 2 = 0010
Uses of BCD
Each denary digit will have a BCD equivalent value which makes it easy to convert from computer
output to denary display.
6
Binary Addition
The binary number system uses only two digits 0 and 1 due to which their
addition is simple. There are four basic operations for binary addition, as
mentioned above.
0+0=0
0+1=1
1+0=1
1+1=10
The above first three equations are very identical to the binary digit number.
The column by column addition of binary is applied below in details. Let us
consider the addition of 11101 and 11011.
Binary Subtraction
0011011
1’s complement can be achieved by converting 0’s to 1’s and 1’s
to 0’s. So the result will be like the following.
1101101 (subtrahend)
+ 1100101 (2’s complement)
________
(MSB) (1)1010010
Practice Exercises
Perform the following binary addtion
8
Perform the following binary subtraction
Overflow
In computing, an overflow error can occur when a calculation is run but the computer is
unable to store the answer correctly. All computers have a predefined range of values they
can represent or store. Overflow errors occur when the execution of a set of instructions
return a value outside of this range.
2. Extended ASCII
This is a set of codes that extends the basic ASCII set. The basic ASCII set uses 7
bits for each character, giving it a total of 128 unique symbols. The extended ASCII
character set uses 8 bits, which gives it an additional 128 characters.
9
3. Unicode
Unicode is a universal character encoding standard. It defines the way individual
characters are represented in text files, web pages, and other types of
documents.
Unlike ASCII, which was designed to represent only basic English characters,
Unicode was designed to support characters from all languages around the
world. The standard ASCII character set only supports 128 characters, while
Unicode can support roughly 1,000,000 characters. While ASCII only uses one
byte to represent each character, Unicode supports up to 4 bytes for each
character.
10
Image representation
Bitmap Images
Bitmap images (also known as raster images) are made up of pixels on a grid. Pixels are
picture elements, i.e tiny dot of individual colour that makes up what you see on your screen.
The dots come together to form the image. Most computer monitors display approximately
70-100 pixels per inch.
Bitmap images are resolution dependent. Resolution is the number of pixels in an image and
it is usually stated as dpi (dots per inch) or ppi (pixels per inch)
Because bitmap images are resolution dependent, it is difficult to increase or decrease their
size without sacrificing a degree of image quality. When the size of a bitmap image is
reduced, we need to “throw away pixels” whereas when the image size is increased, we
need create new pixels. A special software is used for resizing images.
Vector images
Vector images are made up of many individual, scalable objects. These objects are defined
by mathematical equations rather than pixels, so they always render at the highest quality.
Objects may consist of lines, curves and shapes with editable attributes such as colour, fill
and outline. Changing the attributes of a vector object does not affect the objects itself.
Because they are scalable, vector-based images are resolution independent. You can
increase and decrease the size of vector images to any degree. Another advantage of vector
images is that they are not restricted to rectangular shape like bitmaps.
The primary disadvantage of vector images is that they are unsuitable for producing photo-
realistic imagery. Vector images are usually made up of solid areas of colour or gradients,
but they cannot depict the continuous subtle tones of a photograph. That’s why most of the
vector images you see tend to have a cartoon-like appearance.
Vector images primarily originate from software. You can’t scan an image and save it as a
vector file without using special conversion software. On the other hand, vector images can,
quite easily, be converted to bitmaps. This process is called rasterizing.
Image resolution refers to the number of pixels that make up an image ; for example, an
image could contain 4096 x 3192 pixels (12738656 pixels in total). In short, how many pixels
make up an image.
Screen resolution refers to the number of horizontal pixels and the number of vertical pixels
that make up a screen display ( for example , if the screen resolution is smaller than the
11
image resolution then the whole image cannot be shown on the screen or the original
image will now be a lower quality).
When enlarging an image, the number of pixels that makes up the image remains the same
but the area covered is now increased. This means that some sharpness could be lost,
which is known as the Pixel density.
The first image is the original By the time it has been scaled up to make the last image, it
has become ‘fuzzy”. This is so because the first and last image have different pixel
densities.
The main disadvantage of using high resolution images is the increase in file size. As the
number of pixels representing an image is increased, the file size also increases. This
determines how many images can be stored on , for example, a hard drive. It also has an
impact on the time downloading an image from the internet .
Colour depth
It is the number of bits used to represent the colour of a single pixel, e.g a colour depth of
one bit gives a monochrome (black and white) image, and the number of colours per pixel is
21 which equals to two colours.
A colour depth of 2 bits gives 22= 4 colours per pixel.
Colour depth can also be 4 bits, 8 bits or 24 bits.
12
Calculating file size for different colours
Assume there is an image ofresolution
300x225 = 62500 pixels
If the image uses 1 bit to store the colour for each pixel, then the image size would be:
no of pixels * colour depth = image size
13
67500 * 1 = 67500 bits
67500/8 bytes = 67500 / (8*1024) KB
If the image uses 2 bits to store the colour of each pixel.
Image size = 67500 * 2 = 135000 bits
E.g 1) Rectangle
(x,y)
red
Un Texte
blue
14
green
<rect
Width = “100” height = “80”
x = “0” y =”70”
fill = “green” />
<line
x = “5” y = “5”
x2 = “250” y2 = “95”
stroke = “red” />
<circle
Cx = “90” cy = “80” r = “50”
Fill = “blue” />
<text x=”180’ y = “60”
Un Texte
</text>
15
Comparison between Vector graphics and bit-map images
Sound representation
Sound is an analogue wave-form of different volumes and itches (larger energy waves give a
louder sound).
How is sound stored in computers?
Sound waves in nature are continuous. It is therefore difficult to record sound perfectly as
computers can only store discreet data, i.e. data that has a limited number of data points.
Recording sound clip using sampling involves the following:
1. Amplitude of sound wave is first determined at set time intervals (sampling rate)
2. Gives an approximate representation of sound wave
3. Sound wave is then encoded as as series of binary digits
Sampling rate - It is the number of samples taken in one second.
Hertz - It is the S.I unit of frequency defined as the number of cycles per second.
Sampling resolution - It is the number of bits assigned to each sample. The sampling
resolution allows us to set the range of volumes that can be stored for each sample. If you
have a low sampling resolution, then the range of volumes will be very limited. And if you
have a high sampling resolution, then file size may become unfeasible.
16
Longer download time
Greater processing power
File size = sample rate x sample resolution x length of sound
Quest :For the following sound sample work out its size:
Sample rate = 1600Hz, Sample resolution = 8 bits, Length of sound = 10s
File size = 1600 x 8 x 10
= 1280000 bits
17
Run Length Encoding
Run-length encoding (RLE) is a very simple form of data compression in which runs of
data (that is, sequences in which the same data value occurs in many consecutive data
elements) are stored as a single data value and count, rather than as the original run. This is
most useful on data that contains many such runs: for example, relatively simple graphic
images such as icons, line drawings, and animations. It is not useful with files that don't have
many runs as it could potentially double the file size.
Example
For example, consider a screen containing plain black text on a solid white background.
There will be many long runs of white pixels in the blank space, and many short runs of
black pixels within the text. Let us take a hypothetical single scan line, with B representing a
black pixel and W representing white:
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWW
WWWWWWWWBWWWWWWWWWWWWWW
If we apply the run-length encoding (RLE) data compression algorithm to the above
hypothetical scan line, we get the following:
Interpret this as twelve W's, one B, twelve W's, three B's, etc.
18